Some WordPress Plugins will attempt to load jQuery into the document <head>
, but this can have a negative impact on performance.
A better option is to load jQuery near the bottom of the document; here’s how you can force jQuery to appear in the proper location:
add_action('wp_enqueue_scripts', 'move_jquery'); function move_jquery() { wp_scripts()->add_data('jquery', 'group', 1); wp_scripts()->add_data('jquery-core', 'group', 1); wp_scripts()->add_data('jquery-migrate', 'group', 1); }
Using a pro PHP customization class? Try this code instead:
public function front_end() { /* Hooks and filters that affect the front end _only_ go here */ add_action('wp_enqueue_scripts', array($this, 'move_jquery')); } public function move_jquery() { wp_scripts()->add_data('jquery', 'group', 1); wp_scripts()->add_data('jquery-core', 'group', 1); wp_scripts()->add_data('jquery-migrate', 'group', 1); }