Add icons to wp_list_categories
Today when I need to add icons to wp_list_categories, the post from Isabel Castillo showed up in the Google search results, which gave me the idea that wp_list_categories
filter could do the magic.
The only problem is for some reason, I need the icon displayed in the a
tag, the pattern from Castillo’s post didn’t work for me.
I’m really suck at Regular Expression, it took me some time to figure it out:
The $pattern
means “find the start a
tag for me”, and the $1
in the $replacement means “leave the a
tag you found here”, so we could append the icon (css with background image / web font, or simply a gif / png).
I’m a senior web developer helping clients build their websites to grow businesses. Currently I’m based in Taipei, Taiwan.
I write things about WordPress, AngularJS and life. Whenever you’d like to find someone to talk about these topics, just get in touch!