0

I am utilizing the following code to add an additional three Featured Images to homepages in a multisite installation:

if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(
        array(
            'label' => 'Core Home Image 1',
            'id' => 'core-home-1',
            'post_type' => 'page'
        )
    );
    new MultiPostThumbnails(
        array(
            'label' => 'Core Home Image 2',
            'id' => 'core-home-2',
            'post_type' => 'page'
        )
    );
    new MultiPostThumbnails(
        array(
            'label' => 'Core Home Image 3',
            'id' => 'core-home-3',
            'post_type' => 'page'
        )
    );
}

The new edit page widgets are displaying and functioning as they should, however, they are appearing on all edit pages. How do I force WordPress to only display them on the pages that use a specific template, i.e. Core Front Page Template (wp-content/themes/mytheme/templates/core-front-page.php)?

Thanks in advance for your help.

1
  • Try the conditional is_page_template('core-front-page.php') after the function. Commented Jan 20, 2014 at 2:09

1 Answer 1

0

Solution used:

// decide to show or hide the widgets
function check_for_using_template(selected){
    if (selected == "page-templates/core-front-page.php"){
        jQuery("#page-core-home-1").show();
        jQuery("#page-core-home-2").show();
        jQuery("#page-core-home-3").show();
        jQuery("label[for='page-core-home-1-hide']").show();
        jQuery("label[for='page-core-home-2-hide']").show();
        jQuery("label[for='page-core-home-3-hide']").show();
    }else{
        jQuery("#page-core-home-1").hide();
        jQuery("#page-core-home-2").hide();
        jQuery("#page-core-home-3").hide();
        jQuery("label[for='page-core-home-1-hide']").hide();
        jQuery("label[for='page-core-home-2-hide']").hide();
        jQuery("label[for='page-core-home-3-hide']").hide();
    }
}
jQuery(document).ready(function(){
    check_for_using_template(jQuery("#page_template").val());
    jQuery("#page_template").change(function(){
        check_for_using_template(jQuery("#page_template").val());
    })
});

Unfortunately, I was unable to successfully utilized the is_page_template, so I used jQuery. Works, though it may not be the most efficient solution.

Your Answer

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

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