Skip Navigation

[Resolved] Can you hide Content Template and Layout Template Metaboxes for non-admins?

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to hide the Content Template and Template Layout metaboxes from certain role Users.

Solution: It's not possible through wp-admin, but you could use a custom code snippet to hide these boxes.

add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
  if ( ! current_user_can( 'delete_others_pages' ) ) { // Only run if the user is an Author or lower.
    $slugs = array(
      'post',
      'page',
      'custom-cpt-slug',
    );
    remove_meta_box( 'wpddl_template', $slugs, 'side' );
    remove_meta_box( 'views_template', $slugs, 'side' );
  }
}

Modify the $slugs array to include a comma-separated list of each post type slug where you want to hide the metaboxes.

Relevant Documentation:
https://developer.wordpress.org/reference/functions/remove_meta_box/

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by larryB-3 5 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1179360

Tell us what you are trying to do? Is there away to hide the metaboxes on Toolset CPTs for Content Template and for Template Layout for someone in an non-admin role (i.e. author or editor) - I don't want them messing with those.

#1179450

Hi, it will require some custom code with the WordPress remove_meta_box API. Add this code in your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom code:

add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
  if ( ! current_user_can( 'delete_others_pages' ) ) { // Only run if the user is an Author or lower.
    $slugs = array(
      'post',
      'page',
      'custom-cpt-slug',
    );
    remove_meta_box( 'wpddl_template', $slugs, 'side' );
    remove_meta_box( 'views_template', $slugs, 'side' );
  }
}

You'll have to modify the $slugs array to include a comma-separated list of each post type slug where you want to hide the metaboxes.
https://developer.wordpress.org/reference/functions/remove_meta_box/

#1179991

My issue is resolved now. Thank you!