How to Universally Show the Featured Image in the Buddypress Activity Excerpt

Rating: 12
Comments: 2

How to Universally Show the Featured Image in the Buddypress Activity Excerpt

12 Dec 2012 21:19

I came across this problem while I was coding one of my Buddypress installs. One of my installs is completely custom PHP code and I had a situation where the featured image would not show up in the activity stream associated with a blog post.

This Literally took me a year to find/mess with and code the official thing. This code will 100% get the featured image in the specific post id to show up in the associated Buddypress Activity Stream Item's excerpt/content.

Place the Following code in your functions.php file and this will work universally:

// Here is the fix
function icondeposit_bp_activity_entry_meta() {
 
    if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
        <?php
        global $wpdb, $post, $bp;
        $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ) );
        ?>
        <img src="<?php echo $theimg[0]; ?>" >
 
    <?php }
 
}
add_action('bp_activity_excerpt_append_text', 'icondeposit_bp_activity_entry_meta');

Just like my freebie posts, you are required to link back to this site any time you use this code.

update: since the latest Buddypress 1.7 update this code will not work unless you manually edit it.

View the Demo:
Original URL: http://www.icondeposit.com/code:4
License Info: Creative Commons Attribution 3.0

rating: +12+x

Add a New Comment
Copyright © 2011-2019 Icon Deposit - All rights Reserved