0

I know it is possible to have enable post thumbnails on a specific post type, but is there any way of doing this just for specific template?

2 Answers 2

0

You can use the remove_post_type_support for your requirement. In your case, you remove post thumbnail if specific page template is not selected.

function remove_post_thumb(){
    if (isset($_GET['post'])) {
        $post_id = $_GET['post'];
    } else if (isset($_POST['post_ID'])) {
        $post_id = $_POST['post_ID'];
    } else {
        return;
    }
    $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
    if ($template_file != 'page-your-template.php') {
        remove_post_type_support('page', 'thumbnail');
    }
}
3
  • Thanks for this - just tried it, but it doesn't seem to be working (thumbnail still shows regardless of template).
    – user319940
    Jun 28, 2015 at 11:14
  • if your template is in some folder then your condition should be folder/page-your-template.php and also the post meta _wp_page_template might not work unless you save the post once. Try once.
    – Karun
    Jun 28, 2015 at 11:20
  • Just tried, but still the same unfortunately.
    – user319940
    Jun 28, 2015 at 11:23
0

You can use a conditional function to check whether the page being accessed is using a page template and if so, display .... code.

is_page_template( 'about.php' )

The above is the specific function and it could be used in an if statement, like so:

if ( is_page_template( 'my_template.php' ) )
{
    // Display Code
}

You could also do an if/else and display something as an alternative:

if ( is_page_template( 'my_template.php' ) )
{
    // Display Code
}
else
{
    // Display Alternative Code
}

Just the same, instead of checking whether the current page is using the page template, you could check to see if it's not:

if ( !is_page_template( 'my_template.php' ) )
{
    // Display Code or Error
}

More information on Conditionals: https://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.