Skip to main contentSkip to footer

From the Relevanssi settings, you can only choose whether subscribers are indexed or not.

If you need finer control over what user roles are indexed by Relevanssi, you can use the relevanssi_user_index_ok filter hook with the following code. Place it in your theme functions.php:

add_filter( 'relevanssi_user_index_ok', 'rlv_do_not_index_admins', 10, 2 );
function rlv_do_not_index_admins( $do_index, $user ) {
  $block_these_roles = array(
    'administrator',
    'editor',
    'author',
    'contributor',
    'subscriber'
  );
	
  $vars = get_object_vars( $user );
  if ( is_array( $vars['caps'] ) ) {
    foreach ( array_keys( $vars['caps'] ) as $role ) {
      if ( in_array( $role, $block_these_roles, true ) ) {
        $do_index = false;
        break;
      }
    }
  }
  
  return $do_index;
}

Just adjust the $block_these_roles array to include the roles you want to exclude from the index.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

ThemeCo
ThemeCo themes use custom codes for dynamic content. Those are not usual shortcodes, and Relevanssi won’t expand them automatically. In…
Keyword-based search blocking
Update: In Premium 2.15.0 and later versions, you can do spam blocking from Relevanssi settings. Just navigate to the Spam…

Related Posts:

Comment Section:

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed