Sometimes it may be necessary to remove certain WordPress admin input fields based on the assigned template. This can achieved with a simple function that runs on admin load removes certain inputs based on the template filename.


$post_id = $_GET…post_ID’];

 This part is simply getting the post ID from the admin page. This is available on every page which has an ID (pages, posts, custom post types etc). If this is not set, the function returns nothing.


$template_file = get_post_meta($post_id, ‘_wp_page_template’, true);

 The get_post_meta function retrieves one of the pieces of information saved against a page. It takes a post ID parameter to identify what you are editing, a string that contains the information sought, in this case ‘_wp_page_template’ is where WordPress saves the name of the template that the page will use (set via the dropdown on the right hand side). The final parameter just ensures that a single value is returned.


if($template_file == ‘submit.php’) {

 The name of the returned template is then checked. Replace ‘submit.php’ with the name of your template file.


remove_post_type_support(‘page’, ‘editor’);

This will, if the page matches your desired template, remove support for a particular WordPress input field. In this case ‘editor’ removes the main content textarea. This could just as easily be ‘thumbnail’ to remove the featured image option, or ‘excerpt’ to remove the excerpt field.


add_action( ‘admin_init’, ‘hide_editor’ );

 Each function requires a WordPress hook so that it can run at the appropriate time. This is how all of the functions are able to sit in one functions.php file. The ‘admin_init’ argument makes this run on admin pages, and the ‘hide_editor’ argument is a reference to the function name (which can be changed to anything as long as it is changed in both places and doesn’t conflict with other names).