• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Home
  • About
  • My Blogs
    • Photoblog
    • Knots
    • WP.com tips
kristarella.com

kristarella.com

Happiness Engineer at Automattic, lover of knitting, crochet, sci-fi and more

  • Presentations
  • Plugins
    • Exifography
  • Contact
You are here: Home / WordPress / Plugins / bbPress Forum Icons

bbPress Forum Icons

22 April 2013 by kristarella

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.

forum list with icons

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X

Like this:

Like Loading…

Related

Filed Under: Plugins, Tutorials, WordPress Tagged With: PHP

Reader Interactions

Comments

  1. Dawn says

    23 June 2013 at 16:59

    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

  2. kristarella says

    24 June 2013 at 11:04

    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’.

  3. Dawn says

    24 June 2013 at 17:23

    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

Footer

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Categories

%d