Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have multi-author website and I am not very comfortable for allowing all members to enter SEO details in the posts they are publishing. I would like this would be visible only to Administrator of the website. Any ideas?

share|improve this question

5 Answers 5

It didn't say in the API docs on the Yoast SEO plugin site what the ID was and I don't have a copy of Yoast at installed at disposal, but according to yoas-plugin-dir/admin/class-metabox.php line 144, the meta_box registered is;

add_meta_box( 'wpseo_meta', ...etc ); ...

Which is hooked onto add_meta_boxes hook on line 32 of the same file,

add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );

Of course you could get the ID from the meta box itself on the post edit screen... Anyway.

You can do the following,

add_action('add_meta_boxes', 'yoast_is_toast', 99);
function yoast_is_toast(){
    //capability of 'manage_plugins' equals admin, therefore if NOT administrator
    //hide the meta box from all other roles on the following 'post_type' 
    //such as post, page, custom_post_type, etc
    if (!current_user_can('activate_plugins')) {
        remove_meta_box('wpseo_meta', 'post_type', 'normal');
    }
}

...where post type is the post type you wish to apply this restriction too, such as post or a custom post type one or more!

Should do the trick.

update: manage_plugins should have been activate_plugins - ammended.

share|improve this answer
10  
+1 for yoast_is_toast(). –  kaiser Oct 30 '12 at 13:23
    
@Ahmad M thanks for suggested edit but $post_type var and action argument parameter is not required in this instance and does not throw notice/error. Also if you include $post_type var you need to define the post type within the function elsewhere which you did not do, so user would have run this to have it work improperly! In this case its perfectly acceptable to pass in post type name i.e. as 'post' directly into remove_meta_box function. Thanks for suggestion anyway. –  userabuser Oct 30 '12 at 16:39
    
@userabuser: Thanks for clarification, but $post_type is already defined and ready to be used by the add_meta_boxes action hook functions, please see Adam Brown sorce view of this action hook. Utilizing $post_type in this case will make the code independent of the post_type editing screen, meaning it will remove wpseo_meta meta box from all the post types it is found on, and will return nothing in case wpseo_meta is not found. –  Ahmad M Nov 1 '12 at 18:11
    
@AhmadM Thanks mate. I am aware of the var already being defined, however that does not make it a requisite to pass into the hook/function. In this case the OP wants to remove the meta box from the post post_type which is why the initial solution will allow for granular control. However in the case where you want to remove it for all post types then using the already defined var $post_type is satisfactory. What I will do, is edit my answer to include your additional example using the $post_type variable for situations where someone may want to apply this to all registered post_types. –  userabuser Nov 2 '12 at 4:23

You can remove it using the remove_meta_box function.

if ( ! current_user_can( 'edit_pages' ) ) {
    add_action( 'add_meta_boxes', 'my_remove_wp_seo_meta_box', 100000 );
}

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

Notice the 100000 in the add_action, this makes sure that this is done after the WP SEO metabox has been hooked in.

share|improve this answer

Try pasting this in a plugin or theme functions.php file, as per the WordPress SEO plugin (API Docs), by Yoast.

if(function_exists('wpseo_use_page_analysis') && !current_user_can('administrator')){
    add_filter('wpseo_use_page_analysis', '__return_false');
}

To avoid any errors... This checks to make sure the function exists, before attempting to hide stuff, allowing you to deactivate the plugin, and not throw errors.

You may need to hook into init for this to properly work, which could be done so like this:

function wpse_init(){
    if(function_exists('wpseo_use_page_analysis') && !current_user_can('administrator')){
        add_filter('wpseo_use_page_analysis', '__return_false');
    }   
}
add_action('init', 'wpse_init');
share|improve this answer

You can use the Adminimize plugin to hide items from users depending on their roles. Have used this myself to hide some Yoast SEO stuff from clients and simplifying the back end.

http://wordpress.org/extend/plugins/adminimize/

Pretty straight forward to use by adding the css selectors for the items you want to hide. Have used it to hide the SEO Page Analysis tabs (#linkdex)

share|improve this answer

Well there is a setting option on the WordPress SEO by Yoast for disabling the advanced part of WordPress SEO settings for non admins. If you want to completely disable the box then you can use other plugins to remove post editor page elements for non admins, e.g. removing the WordPress SEO box from the post editor for non admins.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.