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'); }
Helped me here in Brazil! Thank you very much!!
thanks a lot, it’s still working!… wasted 2 hours to find a solution
Thank you very much for this! Unfortunately, it only works for the administrator, how can I make this applicable to other user roles?
I’m sorry, that comment was for another thread…
How about removing Yoast SEO on the front-end based on anything? user-role, page or post id? How do I stop the call to yoast seo on the front-end of the site?
I’m not sure why you’d want to remove the front-end part of Yoast, since this would be the SEO attributes (meta descriptions, optimised titles, canonical urls etc.). Also, changing SEO attributes based on role might be seen as some sort of cloaking by Googlebot.
Yoast gives you per-page control of SEO vars – is this not enough? There are some documented hooks in the Yoast API docs. To remove all SEO attributes, I’d look at unhooking the wpseo_head action in your functions.php.
Doesn’t work, contributor can still see yoast seo. I think this is outdated.
This works a treat, thank you!
And for those stuck, this code can just go into the top of your functions.php file and it will work.
However, I personally like my helper functions in a separate file so I moved the `check_user_role` function out of the main `functions.php` file and into a `helpers.php` file.
Robin, this is my adaption of your code – I’ve tried tidying it up a little. 🙂
It would be nice if you let us know “where in what file” to plug this code into?
Yes, you’re right. It goes in your theme’s functions.php.
Where exactly?
Please read the post again to see where to place the code.