It surprised me how long it took me to find anything about adding icons to bbPress forums! It wasn’t until it occurred to me that a useful way to implement them would be to use WordPress featured images and searched for forum featured images that I made some progress.
In the end it is really quite simple!
First you need to enable featured images on the forum post type, then you need to put that image in the right place (I prefer to use a hook action for this when I can).
The code
Just place this code in your theme’s functions.php file.
add_post_type_support('forum', array('thumbnail'));
function ks_forum_icons() {
if ( 'forum' == get_post_type() ) {
global $post;
if ( has_post_thumbnail($post->ID) )
echo get_the_post_thumbnail($post->ID,'thumbnail',array('class' => 'alignleft forum-icon'));
}
}
add_action('bbp_theme_before_forum_title','ks_forum_icons');
The code above does those two things: enables featured images on forums and then hooks the image before the forum title on the bbPress archive page (the one with all the forums listed at once).
Icons on single forum pages
If you want to show the image on single forum pages too the method might vary depending on your theme, since the main forum title on those pages is generated using the regular WordPress the_title()
function.
If you’re using a theme with hooks, like Thesis or Genesis (and most ‘frameworks’, I think), you can use the relevant “before post title” hook to add the same function as above to the relevant hook. E.g., in Genesis you can use add_action('genesis_before_post_title','ks_forum_icons');
There you have it! Forum icons in bbPress.
Dawn says
Thanks for the guide, Krista. That’s what I’ve been wanting to do. May I ask if it’s possible to specify the size of the thumbnail?
Dawn
kristarella says
Dawn, you can either use CSS or you can use add_image_size to add a custom size for your featured images and use that instead of ‘thumbnail’.
Dawn says
Thanks again. What I did was to change the thumbnail size in the media settings but I’ll looked into your option. Hopefully I’ll get it right.
Thanks!
xoxo