07967 325669 info@mootpoint.org

The Yoast WordPress SEO plugin offers great control of your WordPress site’s SEO. Unfortunately, the plugin doesn’t define specific capabilities, which means you cannot restrict access to the WordPress SEO settings to specific roles. In a multi-user site set up, you may not want your editors or contributors to have access to these settings if they don’t know what they’re doing.

Updated in September 2017: With the release of Yoast version 5.5.0, SEO-specific user roles have finally been created, making this solution redundant. Read the post on SEO roles.

This workaround disables the WordPress SEO metabox and the page analysis columns for all roles other than ‘administrator’ and the ‘seo’ role. Place the code in your theme’s functions.php file.

// Returns true if user has specific role 
function check_user_role( $role, $user_id = null ) {
    if ( is_numeric( $user_id ) )
		$user = get_userdata( $user_id );
    else
        $user = wp_get_current_user();
    if ( empty( $user ) )
		return false;
    return in_array( $role, (array) $user->roles );
}

// Disable WordPress SEO meta box for all roles other than administrator and seo
function wpse_init(){
    if( !(check_user_role('seo') || check_user_role('administrator')) ){
    	// Remove page analysis columns from post lists, also SEO status on post editor
        add_filter('wpseo_use_page_analysis', '__return_false');
        // Remove Yoast meta boxes
        add_action('add_meta_boxes', 'disable_seo_metabox', 100000);
    }   
}
add_action('init', 'wpse_init');

function disable_seo_metabox(){
	remove_meta_box('wpseo_meta', 'post', 'normal');
	remove_meta_box('wpseo_meta', 'page', 'normal');
}