How to embed script in wordpress footer


Another “tip of the day”. I ran into this while testing some carousels and swiping banners. All needed the associated js scripts to be loaded lastly after the main page/ post content was already available. It seems that using wp_enqueue_script last argument as true will do the trick:

 * global_js last true means that the script is embedded in the footer
 * @return void
function global_js()
  wp_enqueue_script('js-global', get_theme_file_uri('/assets/js/global.js'), array('jquery'), '1.0', true);

add_action('wp_enqueue_scripts', 'global_js');

Hope you will find this useful. Cheers !


Tidying up my shack

After quite some time when this space was in a mess, today I took almost a quantum leap: organizing everything and make it ready for my next projects was not an easy job. I miss building stuff and this space is perfect for such things. Some of my favourite tools are in the picture: the […]

Why CSS margins collapse

While working on my new theme for this site I ran into a problem: CSS collapsing margins. Well, from the beginning let me be very clear: this will not be a comprehensive article on this subject. There is already one written by Josh Comeau and is excellent: “The Rules of Margin Collapse“. I urge you […]

Leave a Reply

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