wordpress - registering, enqueuing, and adding javascript functions.php -
i know there several posts on here, having gone through ton of them, still having problems. - front end apologies on adding another question on seems straightforward i'm new , stuck!
that beingness said - have soundclick.js. lives in theme's js folder. works pasted straight header - need in functions.php file other little javascripts.
function wpana_js() { wp_register_script('soundclick', get_template_directory_uri() . '/js/soundclick.js', array(), '0', false); wp_enqueue_script('soundclick'); } add_action('wp_enqueue_scripts', 'wpana_js');
code goes in - javascript shows in page source, calls javascript these sounds play on user click don't work anymore. (the calls worked dandy when javascript pasted straight header)
am missing obvious on getting javascript working status? thanks!
update fixed problem - apparently queuing correctly, problem lay in js file itself. there basic problem how made file. showing not working. taking :)
i inspect order in scripts beingness loaded when
it works pasting straight header, versus it's loaded viawp_enqueue_script()
you've done in functions.php
is library getting loaded after javascript code attempts utilize it? soundclick.js jquery plugin?
if need load scripts after others, ensure define dependent scripts in array parameter (for example, if script requires jquery)
wp_register_script('soundclick', get_template_directory_uri() . '/js/soundclick.js', array('jquery'), '0', false);
javascript wordpress
No comments:
Post a Comment