How toHow to set a default icon

Suppose you have categories that don’t have yet an icon assigned to. If you want to display a default icon instead of nothing (no icon), here is the code that you must paste in functions.php (in your theme) :

function bm_noicon($content) {
 if (empty($content)) {
   $content = '<img src="" alt="default icon" />';
 return $content;
add_filter('category_icons', 'bm_noicon');

Of course, you need to replace by your own icon/image URL.

3 thoughts on “How to set a default icon

  1. Pingback: Category Icons » Category Icons Filters

  2. Hi,
    This works great, thanks for the tip!
    Would it be possible to also have a default icon for the small icon, as the code above will display the same default icon for ’small=false’ and ’small=true’ parameters ?

  3. @Pierre
    no, it’s just a tip. Désolé, Pierre. Je ne vois pas de solution immédiate, en tous cas.