public
Last active

Hides Yoast SEO Plugin Field Columns for Author users and below

  • Download Gist
hides-columns.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// Hides Yoast SEO Plugin Field Columns for Author users and below
// @since Jan, 2013
// @author R. Dall
 
if( current_user_can( 'edit_users' ) ) {
// The user can see all columns
}
else {
// The user has the SEO Columns hidden
function my_columns_filter( $columns ) {
unset($columns['wpseo-score']);
unset($columns['wpseo-title']);
unset($columns['wpseo-metadesc']);
unset($columns['wpseo-focuskw']);
return $columns;
}
// Filter pages
add_filter( 'manage_edit-page_columns', 'my_columns_filter',10, 1 );
// Filter Posts
add_filter( 'manage_edit-post_columns', 'my_columns_filter',10, 1 );
// Custom Post Type
add_filter( 'manage_edit-surgeon_columns', 'my_columns_filter',10, 1 );
}

See my fork, you don't want to check current_user_can() every time the page loads, only when the filter is called. The empty if block is unnecessary, and unset can take as many variables as you feed it, not just 1 at a time.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.