Skip to content

Instantly share code, notes, and snippets.

@joelstransky
Last active November 8, 2016 01:41
Show Gist options
  • Save joelstransky/e9377cd2a5823ebbacc8431456c62bdf to your computer and use it in GitHub Desktop.
Save joelstransky/e9377cd2a5823ebbacc8431456c62bdf to your computer and use it in GitHub Desktop.
Hide Yoast SEO meta boxes
<?php
// hide Yoast SEO from non-admin
function hide_yoastseo() {
if ( !current_user_can( 'administrator' ) ) :
remove_action('admin_bar_menu', 'wpseo_admin_bar_menu',95);
remove_menu_page('wpseo_dashboard');
endif;
}
add_action( 'admin_init', 'hide_yoastseo');
function remove_yoastseo_metaboxes() {
if ( ! current_user_can( 'administrator' ) ) {
$wpseo_metabox = $GLOBALS['wpseo_metabox'];
$post_types = get_post_types( array( 'public' => true ) );
if ( is_array( $post_types ) && $post_types !== array() ) {
foreach ( $post_types as $post_type ) {
if ( $wpseo_metabox->is_metabox_hidden( $post_type ) === false ) {
$product_title = 'Yoast SEO';
if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
$product_title .= ' Premium';
}
remove_meta_box( 'wpseo_meta', $post_type, 'normal' );
}
}
}
}
}
add_action( 'add_meta_boxes', 'remove_yoastseo_metaboxes', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment