wp_localize_script & wp_enqueue_script not working in front end
May be try get_template_directory_uri() instead of get_stylesheet_directory_uri(), if your js file is in your theme, it should work frontend. little help I know^^
May be try get_template_directory_uri() instead of get_stylesheet_directory_uri(), if your js file is in your theme, it should work frontend. little help I know^^
Try passing array() for $deps, and NULL for $ver: wp_enqueue_script( $handle, $src, array(), NULL, $in_footer); Or, using your function call: wp_enqueue_script(“myscript” , get_template_directory_uri().”/js/myscript.js”, array(), NULL, true ); By the way, passing the script itself as a dependency to itself will probably make something blow up. Note also: if your script depends on jQuery, just pass … Read more
Since theme developers don’t always enqueue their styles and often hardcode the link, what’s the best way around this? There is no way around this. Simply said: Let them burn. They’re doing it wrong and as a 3rd party code developer you don’t have to take wannabe developers into account.
First, be sure to enable WP_DEBUG in your wp-config.php file, so that you can see fatal error messages. In this case, the problem is that you’ve named your function load_wforms(), but you reference the callback wforms in your add_action() call: function load_wforms() {} …vs… add_action(‘init’, ‘wforms’); The second parameter, wforms, refers to a function named … Read more
Probable Cause I strongly suspect that you do not call wp_head() in your header.php file, immediately before the closing HTML </head> tag: <?php wp_head(); ?> </head> You must call this template tag, in order to fire the wp_head action. The wp_head action in turn fires the wp_enqueue_scripts action. So, without having <?php wp_head(); ?> in … Read more
Edit: new solution, based on one of the comments. If you are using wp_enqueue_script to load your js file, make sure jQuery is a dependency so that it gets called before your code: wp_enqueue_script( ‘my_script’, ‘my-script.js’, array( ‘jquery’), $ver, true ); You can then remove the original enqueue call you had since jQuery will be … Read more
The order of your hooks will cause issues since your loading gavsiu_scripts via wp_enqueue_scripts and your using it to also load your fallback function using script_loader_src. As far as I can tell the only good way to load a fallback script is to not use wp_enqueue_scripts and instead just load your js into wp_head or … Read more
If you’re only enqueueing scripts when they’re needed, you can check in JS if the plugin’s namespace exists before trying to use it: if( $.fn.slider ) { $(‘#slider’).slider(); } or another option is to pass some script vars via wp_localize_script: $wpa_script_data = array( ‘is_front_page’ => is_front_page(), ‘slider_options’ => array( ‘speed’ => 6000 ) ); wp_localize_script( … Read more
I’m not sure but it might have something to do with the html5blank_protocol_relative() function used by HTML5 Blank Theme. You could try removing the filters at L# 382 & 383 of the functions.php file. // Protocol relative URLs for enqueued scripts add_filter( ‘script_loader_src’, ‘html5blank_protocol_relative’ ); // Protocol relative URLs for enqueued styles add_filter( ‘style_loader_src’ , … Read more
console.log() is a JavaScript function. You cannot use it in PHP. Add that to your JavaScripts. The version parameter should not affect the file access. But you can remove that parameter and see if it works then. If it does, your server configuration needs further inspection, because it should also work with the version.