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

Taxonomy archive search
This is a Premium feature and only applies when you index taxonomy terms. This does not apply in free Relevanssi.…
Issues with post order plugins
If you’re getting low-quality results and the weight settings are not affecting the results, the first thing to check is…

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