Yoasts SEO plugin adds a metabox to the post edit screen. I’m trying to remove this for users who aren’t editors or above.
I’ve tried putting a remove_meta_box call in on admin_init, trying to remove the action on $wpseo_metabox but to no avail.
How do I remove this metabox without requiring user intervention (the user should never know the metabox existed, so clicking on screen options is not an option )
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
On remove_meta_box is a note:
Because you can’t remove a meta box until it’s been added, it’s
important to make sure your call to remove_meta_box() happens in the
right sequence.
WordPress SEO adds meta boxes on add_meta_boxes action with default priority – 10, which run after admin_init, so that won’t remove them. Instead you need to hook into add_meta_boxes, but with lower priority – 11, 12, etc.
function mamaduka_remove_metabox() {
if ( ! current_user_can( 'edit_others_posts' ) )
remove_meta_box( 'wpseo_meta', 'post', 'normal' );
}
add_action( 'add_meta_boxes', 'mamaduka_remove_metabox', 11 );
Method 2
Remove metaboxes for non-admin accounts:
add_filter ( 'manage_edit-post_columns', 'rkv_remove_columns' );
function rkv_remove_columns( $columns ) {
if ( ! current_user_can('administrator') ) {
unset( $columns['wpseo-score'] );
unset( $columns['wpseo-title'] );
unset( $columns['wpseo-metadesc'] );
unset( $columns['wpseo-focuskw'] );
}
return $columns;
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0