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.

  • Did you try to use the body classes? They are different for the different templates.
    – Badan
    Commented 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(). Commented Mar 28, 2022 at 4:03

1 Answer 1


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:

    if ( $('body').hasClass('page')) {
        // add your logic here

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.