1

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?

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

1
0

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.

0
1

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();

});
2
  • Sorry G. M I tried s_ha_dum's responce first and it worked, as far as I can see your responce is equally amazing however, if I could tick you both I would!
    – leannekera
    Sep 1 '13 at 19:32
  • When I aswered @s_ha_dum answer was not there (or I would not have answered), I think we answer at the same time (now I see answered 17 mins ago for both)
    – gmazzap
    Sep 1 '13 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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