[BuddyPress Activity +] Wordpress Buddypress Activity

The buddypress plugin is pulling new blog post along with the featured image into the activity stream as they are published but the featured image is not clickable. Are you able to direct me to the file where I can add a permalink to the image? Would this be done from bp-custom.php?

  • Ash

    Hello Anthony

    Please try the following code:

    add_filter( 'bp_get_activity_content_body', function( $content, $pointer ) {
    	$link = get_permalink( $pointer->secondary_item_id );
    
    	$content = preg_replace('/(<img[^>]+>)/', '<a href="' . $link . '">$1</a>', $content);
    	return $content;
    
    }, 99, 2 );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Anthony

    Thank You as the code did end up doing what I was looking for, but it made some things in the activity stream re-route to the homepage. Is there a template in buddypress that directly outputs the activity for a new blog post? Am I able to add a permalink to the image via that page? My thinking is that the link I need is already available in the title. I just want to take that code and add it to the image making it clickable as well.

    Thanks for any help you can provide, I am really appreciative!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.