Hide metabox dependant on page template chosen

I’m using the following JQuery script from this answer to toggle the display of metaboxes dependant on the Page Template selected. The example below shows the featured image metabox when the default template is selected:

(function($){
$(function() {

    $('#page_template').change(function() {
        $('#postimagediv').toggle($(this).val() == 'default');
    }).change();

});
})(jQuery);

My possibly simple question is… How do I get this code to only show the featured image box for my Page Template entitled: Services?

Read More

I have tried simply changing the 'default' to ‘Services' but no luck.

Related posts

2 comments

  1. The value is not the same thing that you see when you look at the toggle. That part is for humans. To see the value you have to look at the source of the page. If you have a template created by template.contact.php the value in that box would be template.contact.php, so it looks like the value is the php file name.

  2. The value of the select is setted to the file name so, assuming youf template file is services.php

    jQuery().ready(function($) {
    
    var $featImgDiv = $('#postimagediv');
    
    $('#page_template').change(function() {
        if ( $(this).val() == 'services.php' ) {
          $featImgDiv.show();
        } else {
           $featImgDiv.hide();
        }
    }).change();
    
    });
    

Comments are closed.