Home › Toolset Professional Support › [Resolved] Can you hide Content Template and Layout Template Metaboxes for non-admins?
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 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: Types plugin
This topic contains 2 replies, has 2 voices.
Last updated by larryB-3 5 years, 10 months ago.
Assisted by: Christian Cox.
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.
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/
My issue is resolved now. Thank you!