Move scripts to footer

Home Forums Calendar Products Events Calendar PRO Move scripts to footer

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #42336
    Shaun
    Participant

    I’d like to move all my WordPress scripts to the footer to speed up the loading of the pages.

    WordPress has a function that lets you do this when enqueuing scripts http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    However the scripts with the events calendar are loaded at the top.

    Can you update the plugin to instead load them in the footer? Or is there a snipped of code I can add to my functions.php that will deregister your scripts and move them to the footer?

    Thanks
    Shaun

    #42359
    Jonah
    Participant

    Hi Shaun,

    Here is an example of de-queueing one of our scripts and then registering and enqueueing your own. This should steer you in the right direction. Let me know if you need anything else.

    /*-------------------------------------------------------------------------------
    Add Custom events.js
    -------------------------------------------------------------------------------*/
    function example_enqueue_scripts() {
    wp_dequeue_script('tribe-events-calendar-script');
    wp_register_script('custom-events-calendar-script', get_template_directory_uri().'/js/events.js'); // notice it's not the same script name as the original one, that's important - otherwise it re-enqueues the old version
    wp_enqueue_script('custom-events-calendar-script');
    }
    add_action('wp_enqueue_scripts', 'example_enqueue_scripts');

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Move scripts to footer’ is closed to new replies.