• About
  • Advertise
  • Privacy & Policy
  • Contact
djavupixel.com
  • Home
  • Design
    • Fonts
    • Icons
    • Logo
    • Photography
    • Wallpapers
  • Development
    • CSS
    • JS
    • Web
  • WordPress
  • Contact
No Result
View All Result
  • Home
  • Design
    • Fonts
    • Icons
    • Logo
    • Photography
    • Wallpapers
  • Development
    • CSS
    • JS
    • Web
  • WordPress
  • Contact
No Result
View All Result
djavupixel.com
No Result
View All Result
Home Development

Tutorial adding latest jQuery Version to WordPress with wp_enqueue_script()

djavupixel by djavupixel
November 23, 2013
in Development, Wordpress
190
0
606
SHARES
2k
VIEWS
Share on FacebookShare on Twitter

After having used jQuery and WordPress together on a number of themes, I thought I’d share some tips that I have learned through my experience with WordPress.

The traditional way to include jQuery in an HTML page is with the script tag. However when working with WordPress, you should never do this. The reason is to avoid conflicts and other potential problems such as erros with other plugins. Here is how WordPress recommends to load jQuery using the following code:

Code

/**
 * Enqueue jQuery script
 */
function load_jQuery_script() {	
	if (!is_admin()) {
		wp_deregister_script('jquery'); 
		wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js', array(), '', false); 
		wp_enqueue_script('jquery');
	}	
}
add_action( 'wp_enqueue_scripts', 'load_jQuery_script' );

What did we do?

if (!is_admin()): The is_admin() check is to prevent script queuing on your admin pages.
wp_deregister_script: De-registers the WordPress stock jquery script, so you can register your own copy.
wp_register_script: Registers the latest version of jQuery from the jQuery page. So you are sure to use the latest one and from the main source.
wp_enqueue_script: Give it the jquery name for the dependencies

You can replace load_jQuery_script with something more meaningful, but choose a unique name to avoid conflicts. For plugin development, add the code in your plugin file, otherwise, add this code to your theme’s functions.php file.

Load jQuery in the footer

/**
 * Enqueue jQuery script
 */
function load_jQuery_script() {	
	if (!is_admin()) {
		wp_deregister_script('jquery'); 
		wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js', array(), '', true); 
		wp_enqueue_script('jquery');
	}	
}
add_action( 'wp_enqueue_scripts', 'load_jQuery_script' );

Just change in the wp_register_script(‘jquery’, ‘http://code.jquery.com/jquery-latest.min.js’, array(), ”, true); to ture.

Hope this quick tutorial helped you!

Previous Post

jQuery Plugins from Parallax to Navigation

Next Post

Quick way on how to show hidden files in OSX

Next Post
Quick way on how to show hidden files in OSX

Quick way on how to show hidden files in OSX

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • CSS
  • Design
  • Development
  • Fonts
  • Icons
  • JS
  • Logo
  • MacOS
  • Photography
  • Uncategorized
  • Wallpapers
  • Web
  • Wordpress

Tags

Air apple car Chrome city Coding communication Corporate Identity Cross Site Scriptings css Design e-Commerce Earth Extensions Free Google Gradient Styles grd Guideline Icons iPhone iPhone4 JavaScript jQuery Landscape Logo mac Nature Navigation osx Photography Photoshop php plugins PSD Sans-Serif security Serif setup SQL Injections Tutorial Water Wordpress WP e-Commerce xss
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Review
  • Apple
  • Applications
  • Computers
  • Gaming
  • Gear
    • Audio
    • Camera
    • Smartphone
  • Microsoft
  • Photography
  • Security

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.