Run JS function when JQ enqueued

You can’t do that way first you need to enqueue your script using : wp_enqueue_script(‘jquery’); wp_enqueue_script(‘ns-likes-dislikes-for-posts-js’, plugin_dir_url(__FILE__). ‘path/to/your/js/file/from/plugin/directory/custom.js’, array(‘jquery’), ‘1.0’, true); in custom js start writing your js with jquery but you can’t use $, instead use jQuery. if you want to use $ instead of jQuery try this code: (function($){ // enjoy jquery with … Read more

Enqueue Script in WordPress

Your first snippet sets $in_footer to false so the the script will be added to the <head /> of your document. The second snippet sets $in_footer to true and so it will be added at the bottom of your document (usually just before </body>, but it depends on where wp_footer() is called in your theme). … Read more

Loading a newer version of jQuery within WordPress

To replace the default jQuery url, do: wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘your custom url’, … ); Then call wp_enqueue_script( ‘jquery’ ); as usual. Note that various pages in the WP admin might not be compatible with never versions of jQuery, not to mention plugin scripts.

registering new jQuery after wp_deregister_script() not working

When setting your dependencies they need to be in an array. wp_register_script(‘jquery’, ‘http://code.jquery.com/jquery-1.7.min.js’, ‘1.7’, 1); wp_register_script(‘modernizr’, get_bloginfo(‘template_directory’).’/js/libs/modernizr-2.0.6.min.js’, array(‘jquery’) ); wp_register_script(‘plugins’, get_bloginfo(‘template_directory’).’/js/plugins.js’, array(‘jquery’), ”, 1); wp_register_script(‘custom’, get_bloginfo(‘template_directory’).’/js/script.js’, array( ‘jquery’) , ”, 1);

Enqueue script on every page except one

Try giving your function its own parameters and do a template_redirect, something like this: <?php function mypage_scripts() { if ( !is_admin() ) { wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js’, true, ‘1.6.2’, false); wp_enqueue_script(‘jquery’); /* My Script */ function contact_form_script() { if ( !is_page(‘contact’) ) { wp_enqueue_script(‘myscript’, get_bloginfo(‘template_url’) . ‘/js/myscript.js’, array(‘jquery’), ‘1.1’, false); } } add_action( ‘template_redirect’, ‘contact_form_script’ ); … Read more

unable to wp_enqueue_script(‘suggest’);

As stated on WP Devel, you should always use the appropriate hooks. Else no child theme could deregister the script later. // In your functions.php file function add_suggest_script() { wp_enqueue_script( ‘suggest’, get_bloginfo(‘wpurl’).’/wp-includes/js/jquery/suggest.js’, array(), ”, true ); } add_action( ‘wp_enqueue_scripts’, ‘add_suggest_script’ ); This will load the script from the includes folder and stick in your footer … Read more