[Resolved] Remove ‘Content Template’ and ‘Template Layout’ widgets for Editors
This thread is resolved. Here is a description of the problem and solution.
Problem:
Remove 'Content Template' and 'Template Layout' widgets/metabox for certain CPT in admin screen.
Solution:
Please add this code in your theme’s or child theme’s functions.php file:
add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
remove_meta_box( 'wpddl_template', 'book', 'side' ); // replace book with your CPT slug
remove_meta_box( 'views_template', 'book', 'side' ); // replace book with your CPT slug
}
==> Whereas 'book' should be replaced with your CPT slug.
Tell us what you are trying to do?
I am trying to remove the Content Template and Template Layout boxes from a custom post (Called 'Church Listings') for Editors only. I've tried the below link (which I understand should remove these for posts/pages for everyone - correct?), but this isn't doing as expected either.
Thank you for contacting Toolset support. Toolset does not have any option for it. The code given in other ticket is only for Posts and Pages. For custom post type you need to add another linke with your CPT slug, for example if your CPT slug is ‘book’ you would update the code like this:
add_action( 'admin_head', 'my_admin_head', 20);
function my_admin_head()
{
remove_meta_box( 'views_template', 'post', 'side' );
remove_meta_box( 'views_template', 'page', 'side' );
remove_meta_box( 'views_template', 'book', 'side' ); // replace book with your CPT slug
}
Please ensure and double check that slug name you will replace in above code is correct.
Thank you
Thanks for confirming. When implemented, I am given this warning:
Fatal error: Cannot redeclare my_admin_head() (previously declared in /home/mstogether/public_html/wp-content/themes/Divi-child/functions.php:7) in /home/mstogether/public_html/wp-content/themes/Divi/functions.php on line 8928
This error shows because you might have this function already in your functions.php file, please remove all custom code you have added till now for removing this metabox or widget. I have reproduced the same solution at my end, and it is working as expected.
Please try the below code and make sure to replace ‘book’ with your CPT slug. Line #3 is for removing Layouts metabox and Line #4 is for Content Template metabox.
add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
remove_meta_box( 'wpddl_template', 'book', 'side' ); // replace book with your CPT slug
remove_meta_box( 'views_template', 'book', 'side' ); // replace book with your CPT slug
}