WordPress Enqueue Script and Styles Into Footer

function add_scipts() { if (!is_admin()) { wp_deregister_script('jquery'); wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', '', true, '3.1.x'); wp_enqueue_script('jquery'); wp_enqueue_script( 'bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js', array('jquery'), '3.3.4', true ); wp_enqueue_script( 'fontawesomejs', '//use.fontawesome.com/0a1b8c9dce.js', array('jquery'), '3.3.4', true ); } } add_action('init', 'add_scipts'); function prefix_add_footer_styles() { wp_enqueue_style( 'styles', get_template_directory_uri() . '/css/style.css',true,'1.1','all'); wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css',true,'1.1','all'); wp_enqueue_style( 'pingendoCss', get_template_directory_uri() . '/css/pingindo_bootstrap.css',true,'1.1','all'); }; add_action( 'get_footer', 'prefix_add_footer_styles' );
Add this to your WordPress theme's functions.php file.
This correctly puts your scripts and styles into the footer which helps with google page speed. Before doing the enqueue properly I was getting about a 61-67 on google page speed insights. After I did this I got a 97, removing all render blocking javascript and css. As an aside the third parameter on line 5 in between the jquery url and the fourth parameter true need to be blank like I have in this example. That is the dependency value that we're not using because Jquery has no dependencies. If you don't have those single quotes with no value it will not load in the footer.

https://developers.google.com/speed/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.