0

With php there is a wordpress function is_page_template()

Is there a similar function written in jquery/javascript?

To use with the wp.customize api and jquery/javascript.

2
  • Did you try to use the body classes? They are different for the different templates.
    – Badan
    Mar 27, 2022 at 17:41
  • In the customizer or in the preview? If you want to conditionally show customizer controls based this is already supported with the active_callback argument for add_control(). Mar 28, 2022 at 4:03

1 Answer 1

2

Well, yes, in WordPress, different templates have a different body class name. If you inspect the body classes on a specific page in WordPress, there should be a body class page. You can detect the template by checking if the class exists like so:

jQuery(document).ready(function($){
    if ( $('body').hasClass('page')) {
        // add your logic here
    }
});

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.