avatar Deluxe Blog Tips About Projects

bbPress SEO

There are some pages in bbPress that should not be indexed such as:

  • Topic tag
  • User profile
  • Search results

I'll create a function to check the condition as follows:

function dbt_bbpress_noindex() {
    return bbp_is_topic_tag() || bbp_is_single_user() || bbp_is_user_home() || bbp_is_search() || bbp_is_search_results();
}

All SEO plugins have filters to set pages no-indexed. In this post, we'll do that for Yoast SEO and Slim SEO.

For Yoast SEO:

add_filter( 'wpseo_robots_array', function( $robots ) {
    if ( dbt_bbpress_noindex() ) {
        $robots['index'] = 'noindex';
    }
    return $robots;
} );

For Slim SEO:

add_filter( 'slim_seo_robots_index', function( $value ) {
    return dbt_bbpress_noindex() ? false : $value;
} );

Comments