Add Glyphicons to wp_list_categories

Add Twitter Bootstrap Glyphicons to individual list items in wp_list_categories. Do this by modifying the wp_list_categories. Easy peasy by adding a filter. No forsaken Walker needed. My example below adds the ‘icon-book’ glyphicon to each list item generated by wp_list_categories. For all the possible icons you can choose from, see the Twitter Bootstrap stylesheet (bootstrap.css).


/**
* add glyphicons to wp_list_categories 'id="icon-book" 
*/

function isa_add_icons_wp_list_cats($wp_list_categories) {
		$pattern = '/<a/';
		$replacement = '<i class="icon-book"></i><a';
		return preg_replace($pattern, $replacement, $wp_list_categories);
}
add_filter('wp_list_categories','isa_add_icons_wp_list_cats');

See more: ,

We've 2 Responses

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]