Software Developer

Add Font Awesome Icons to wp_categories List Items

This adds one Font Awesome icon to each list item in the WordPress Categories template tag, “wp_list_categories”. (The same icon will be applied to each list item.)

This is done using a filter function which should go in a functions file. This example adds the “checkered flag” icon. You can choose your own icon from the Font Awesome icons page. On that page, click on an icon to see it’s class name. Copy your icon’s class into line 14 below. Replace the “fa-flag-checkered” with your desired icon’s class.

/**
* load Font Awesome style
*/
function smartestt_enqueue_fa() {
	wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
}
add_action('wp_enqueue_scripts','smartestt_enqueue_fa');

/**
* add a Font Awesome Icon to wp_list_categories
*/
function add_icons_wp_list_cats($wp_list_categories) {
	$pattern = '/<a/';
	$replacement = '<i class="fa fa-flag-checkered"></i><a';
	return preg_replace($pattern, $replacement, $wp_list_categories);
}

By

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]