Created
January 17, 2020 15:21
-
-
Save vbaimas/d7f992ad0fb8ff31553e736e6e2b05b3 to your computer and use it in GitHub Desktop.
Disable the Yoast SEO meta box and the page analysis columns for all roles other than administrator and also disable the Yoast SEO meta box in the content types like "post", "page" and "custom post type".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns true if user has specific role | |
function {your_prefix}_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 Yoast SEO meta box for all roles other than administrator | |
function {your_prefix}_wpse_init(){ | |
if( !({your_prefix}_check_user_role('seo') || {your_prefix}_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', '{your_prefix}_disable_seo_metabox', 100000); | |
} | |
} | |
add_action('init', '{your_prefix}_wpse_init'); | |
function {your_prefix}_disable_seo_metabox(){ | |
remove_meta_box('wpseo_meta', '{your_custom_post_type}', 'normal'); // Remove from custom post type | |
remove_meta_box('wpseo_meta', 'post', 'normal'); // Remove from post | |
remove_meta_box('wpseo_meta', 'page', 'normal'); // Remove from page | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment