Skip Navigation

[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.

Relevant Documentation:
https://codex.wordpress.org/Function_Reference/remove_meta_box

0% of people find this useful.

This support ticket is created 5 years, 3 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Tom Nicholson 5 years, 3 months ago.

Assigned support staff: Noman.

Author
Posts
#560569
Screen Shot 2017-08-16 at 21.22.28.png

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.

Is there any documentation that you are following?
https://toolset.com/forums/topic/how-to-hide-content-template-box-from-articles/

Using a Divi with a custom child theme, but it has its own functions.php.

#560716

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Tom,

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

#561295

Hi Noman,

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

#561358

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Tom,

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
}

Thanks

#562442

Hey Noman,

That works great, thank you!