I have a custom page template where I would like to load some javascript. I suppose I could always include the javascript in the actual file, but that seems ugly. Is there any way to identify if WordPress is loading my custom-page.php file so I can enqueue the script only on that page?
It should work dynamically, so checking page id is not an option.
You can use
is_page_template
to check if you template is being used and load your scripts based on that ex:Add this code to your functions.php:
You can use something like this …..
You can add new
wp_enqueue_scripts
in your template file beforeget_header()
call: