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

Modernize
Modernize is a neat Premium theme that has a problem with Relevanssi. Relevanssi highlighting can cause problems on Modernize search…
MemberPress Downloads add-on
The Downloads add-on for MemberPress adds downloadable files to MemberPress. These files are stored outside the Media Library, so by…

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