Hot answers tagged

3

To extend on @gmazzap suggestion on not using globals when you can use wp_scripts(), there is a shortcut for wp_scripts() for adding conditional comments called wp_script_add_data and likewise wp_style_add_data for conditional styles. So the correct way to use conditionals as of Wordpress 4.2 is like this: /** * IE enqueue HTML5shiv with conditionals * ...


2

You just have your arguments lined up wrong. Change the line to wp_enqueue_script( 'ajax-products', plugins_url( '/js/ajax.js', __FILE__ ), array('jquery'), '1.2', false ); You can use plugins_url() with the second parameter of __FILE__ to get the directory of the specific pluign, and in the first argument you pass the relative location of your script. ...


2

Your code seems correct, but it will load the script only in admin area beacuse you are enqueuing the script in admin_enqueue_scripts action. To load the script in frontend, use wp_enqueue_scripts action (which is not the same that wp_enqueue_script() function): function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', ...


2

You can enqueue all your scripts the same way as you enqueue jQuery. Register and enqueue all your Javascripts like this (in your load_jquery function) wp_register_script ( 'yourscripthandle', //string $handle: a string to identify this script get_bloginfo( 'template_url' ) . '/js/yourcustomjs.js', //string $src: Path of your script file array ...


1

Could you not just pass the different string? wp_script_add_data( 'foo', 'conditional', '(gt IE 6)&(lt IE 9)' ); Which by the way is probably the same as: wp_script_add_data( 'foo', 'conditional', '(IE 7)|(IE 8)' ); IE conditionals are pretty unreliable so need to be tested.


1

Here's how localization works. The first thing you need to do is register your script with WordPress. This pretty much tells WordPress where the script is located, what version it is, any dependants ( like jquery ), and whether it will be located in the header or footer. More importantly you need to give it a unique identifier which you'll be able to ...


1

I have not directly an answer to solve your issue as it (please take a look at the edit part I add), but this codesnippet (function) could maybe help you to solve the version issues for .js as well for .css files. /** * Remove query (output)string from .js / .css * Using filters */ function wpse215386_remove_script_version( $src ){ $parts = explode( ...



Only top voted, non community-wiki answers of a minimum length are eligible