The code below creates a plugin that appends the contents of $content to "the_content" on the hompage. It works fine when I set $content to a static value. However, I'm trying to set it to draw out the site's active categories as a list. However, nothing happens when I set $content to wp_list_categories()

Ultimately, I want to hack into the wp_list_categories function and display the thumbnail image that's been assigned to the category (still have to enable the code to do that as well).

This is the first evolution of the plugin and I'm just attempting to get it to list the categories and descriptions before I build in the thumbnail support.

Plugin Name: List Categories with Thumbnail Images

add_filter( 'the_content', 'cb_category_listing' );

function cb_category_listing( $content )
    if ( is_home() ) {
//      $content .= '<p>Hello World!</p>';
        $cat_args['title_li'] = '';
        $myContent = wp_list_categories(apply_filters('widget_categories_args', $cat_args)); 
        $content .= $myContent;
    return $content;

add_action( 'init','cb_category_listing');

Hi @Scott B:

Your example doesn't work for me when I use if (is_home()) but does when I use if (is_front_page()). Is there any chance that is the problem?

Other than that it seems to work fine on my WordPress v3.0.3 install. Do you have other plugins that might be disabling the output of wp_list_categories()?

P.S. I'm assuming you are using add_action( 'init','cb_category_listing'); just for debugging and not as part of your plugin?


You should add argument echo to get returned html string of wp_list_categories, instead of displaying it:

$cat_args['echo'] = 0;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.