This is rather basic, and maybe it's a duplicate question, so let me know where exactly is answered in that case.
I need to add a very simple jQuery script inside my Page Template. I'm using Openstrap theme and I can see that jQuery is loaded on every page, so I thought I could insert my script normally but doesn't work.
After reading some posts, I've seen that I have to use wp_enqueued_script
function, however I just need to load the script on the Page Template only, not every page.
edit
It worked! I changed it to is_singular($post_type) for my needs, and it works as expected. However, the jQuery script isn't doing anything.
Inside functions.php,
/* loader iframes */
function loader_iframe() {
if ( is_singular('farmacia') ) {
wp_enqueue_script( 'loader-iframe', get_template_directory_uri() . '/js/loader-iframe.js', array( 'jquery' ));
}
}
add_action( 'wp_enqueue_scripts', 'loader_iframe' );
Inside js/loader-iframe.js,
$(function() {
$('.loader-iframe').on('load', function(){
$('.loader-iframe').find('img').hide();
});
});