Move JS in the footer // Adapt functions.php

  • Author
  • #3771

    Hello guys (and ladies),

    First of all a big thank you for this great customizable theme!

    I am adapting it further with a child theme and I d like to move JS scripts to the footer to make the website load faster. I ve found this code to do so:

    <code>// Move All Javascript to Footer

    remove_action('wp_head', 'wp_print_scripts');
    remove_action('wp_head', 'wp_print_head_scripts', 9);
    remove_action('wp_head', 'wp_enqueue_scripts', 1);
    add_action('wp_footer', 'wp_print_scripts', 5);
    add_action('wp_footer', 'wp_enqueue_scripts', 5);
    add_action('wp_footer', 'wp_print_head_scripts', 5);


    But as mentionned in functions.php I shouldn’t change anything in it… As it refers to other functions.php files I wonder if I could adapt these?

    And if it’s the case in which one I could set this code… (theme-functions.php?)?

    I have been looking for documentation about these without finding it. In fact being up to adapt them could avoid the use of too many plugins.

    Many thanks in advance for your help!

    Have a nice day!



    Cryout Creations mastermind

    You should put all your code into the child theme’s functions.php file.

    Note that (as I have found out the hard way) not all actions are removed properly by just using remove_action(). Also, note that Mantra has more hook functions than the ones listed in your sample code.

    The safest way is to use a wrapper function:

    function remove_mantra_functions() {
    // insert all your remove_action calls here

    then use add_action() to attach your child theme function replacements.

    If you like our creations, help us share by rating them on
    Please check the available documentation and search the forums before starting a topic.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Move JS in the footer // Adapt functions.php’ is closed to new replies.