jQuery will not work on page from snippet or file
The file was reading from parent theme directory not the child theme directory thus the issue of it not being read. Found it from tracing the directory from the Network tab
The file was reading from parent theme directory not the child theme directory thus the issue of it not being read. Found it from tracing the directory from the Network tab
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
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
There is is_page_template() conditional tag to check for that.
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.
WordPress 3.1 hides some of these options. If you go to edit a post, look on the upper right of your screen. You will see “screen options.” From there, you can click custom fields (as well as other options).
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);
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
wp_enqueue_script accepts 5 parameters. The fifth one is $in_footer. If that parameter is set to true the script will load in the footer. If it is set to false it will load in the head, unless a dependency (like jQuery in your code) is set to show up in the footer.
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