Category Icons Filters

There are 2 filters :

1. category_icons

It can be used with the get_cat_icon tag. Examples of how to use it :

How to set a default icon

How to assign a specific icon for a post

How to modify the category icons through functions.php

2. category_icons_widget

It can be used with put_cat_icons tag. A how to needs to be written.

Function : put_cat_icons()

This function “iconizes” your categories list in the sidebar.

put_cat_icons(list [,get_cat_icon_parameters] [,’icons_only=true’])

  • list : this is a WordPress category list : wp_list_categories(). You MUST ADD echo=0 to the wp_list_categories parameters.
  • get_cat_icon_parameters : (optional) these are the get_cat_icon() parameters, separated by a ‘&’.
    There’s an exception : for put_cat_icons(), the parameter ‘link’ is always set to false.

Example :

write the following code in sidebar.php to have icon next to the category name for which you uploaded an icon. You can give any parameters to wp_list_categories, but you MUST ADD echo=0, in order to process the list :

if (function_exists('put_cat_icons'))

In the parameters, if you put : ‘icons_only=true’, then only the icons will be displayed in the sidebar, instead of the icon AND the category name. Look at the 2nd line :

if (function_exists('put_cat_icons'))

If you use the widget, just put icons_only=true in the parameters :



Function : get_cat_icon()

The size of the icons depends on your needs & theme. There’s no recommanded size to use the get_cat_icon() function.

The function get_cat_icon() return boolean True if an image is found. You can use the following parameters.

type parameter summary
boolean align align attribute for the image tag
boolean border If true, displays the icon with a border. If false, no border is diplayed. (Don’t use this if you want valid Strict XHTML)
int cat Category ID. If not specified, the current category is used or the current post’s category.
string class Class attribute for the image tag.
boolean echo If true the html code will be ‘echoed’. If no, it’ll be returned. Default : true
boolean expand Whether the image should be expanded to fit the rectangle specified by fit_xxx. Default : false
int fit_height Maximum height (or desired height if expand=true) of the image. Default : -1
int fit_width Maximum width of the image, or desired width if expand is true. Default : -1
boolean hierarchical If true, displays the icon in hierarchical order. Default : false
boolean link If true, an anchor tag wraps the image (a link to the category is made). Default : true
int max_icons Maximum number of icons to display. Default : 3
string prefix String to echo before the image tag. If no image, no output.
boolean small Use the small icon. Default : true.
string suffix String to echo after the image tag. Ignored if no image found.
boolean use_priority If true, only the most prioritized icon will be displayed. Default : false


This example will insert the icon associated with the current category:

<?php get_cat_icon(); ?>

Here is an example of how to use it in index.php of your theme directory :

<div class="left_side">
if (have_posts()) :
  while (have_posts()) : the_post();
    if (function_exists('get_cat_icon'))

Example of class attribute for the image :

.myicons {
margin : 0 3px 0px 0;

This example inserts icon for the category with ID ‘5′. The image is fitted withing rectangle 100×100. If the image is smaller than desired, it is expanded :

<?php get_cat_icon('cat=5&fit_width=100&height=100&expand=true'); ?>

More examples.

If you’re wondering : where to put the get_cat_icon() code, read this.