It’s usually better to set the robots meta of user profile pages, forum topics and replies to noindex so that they don’t dilute your SEO effort on your main content pages. Fortunately, bbPress user profile robots meta is noindexed by default. If the bbPress user profile page is set to index on your website and you’re using Rank Math, then this short tutorial will show how to change it.

You’ll need two main things in your code; A filter to modify the the meta robots value and a conditional to check if you’re on a user profile page.

The Filter for Rank Math Robots Meta

The filter below hooks into ‘rankmath/frontent/robots’ and returns an array of robots meta values:

add_filter( 'rank_math/frontend/robots', function( $robots ) {
   //Do some stuff
   return $robots;
});

The bbPress Profile Page Conditional

Check if the current page is a bbPress profile page with this snippet:

if (bbp_is_single_user_profile()) {
   // do your stuff
}

The final filter code snippet

This is what you’ll use in the end:

/**
 * Sets bbPress user profile pages to noindex
 *
 * @param array $robots The meta robots directives.
 */
add_filter( 'rank_math/frontend/robots', function( $robots ) {
    
    if (!bbp_is_single_user_profile()) {
        return $robots;
        }
    unset( $robots['index']);
    $robots['noindex'] = 'noindex';
    return $robots;
});

Video

Below is a video of me testing the code snippet on a local setup with only bbPress and Rank Math installed:

Conclusion

Did I do it the long way round, or did I miss something? Did you use this tutorial for your own website and discover something, or just want to say hi? Let me know in the comments section below.

Leave a comment

Your email address will not be published. Required fields are marked *