Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1256808
    Guma
    Participant

    Hello, i have pretty simple page so i dont have issues to move all JS to footer.
    The problem is, that whatever code i add to the functions.php its not working.

    I have tried several codes like:

    Solution1:
    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);

    Solution2:
    if(!is_admin()) {
    // Move all JS from header 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);
    }

    and several similar one, but nothing is working…could someone review my functions.php file?

    thanks
    Peter

    #1256813
    Guma
    Participant
    This reply has been marked as private.
    #1257110
    Jade
    Moderator

    Hi there,

    You might want to check out this plugin: https://wordpress.org/plugins/scripts-to-footerphp/

    Hope this helps.

    #1257521
    Guma
    Participant

    Hello, i tried this plugin and its not conpatible with WP Rocket which i use.
    I tried the guide of that plugin, to make it works together, however it completely mess the site.
    I would prefer the option with the functions.php.
    Thx

    #1257688
    Thai
    Moderator

    Hi There,

    Please try with this code instead:

    add_action( 'init', 'move_scripts_to_footer' );
    function move_scripts_to_footer(){
    	if(!is_admin()) {
    		
    		// Move all JS from header 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);
    	}
    }

    Hope it helps 🙂

    #1258020
    Guma
    Participant

    Hello, thanks for the code provided and your time.
    I put it to the folder /web/wp-content/themes/x/functions.php and its not wroking.
    JS is still on the header according google speed insights and gtmetrix.

    I dont get it 🙂 code works for someone and for someone not.. 😀

    thx

    #1258313
    Nabeel A
    Moderator

    Hi again,

    Please don’t add the code in your parent theme, add it in your Child Theme. If you don’t have the Child Theme yet then I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Let us know how this goes!

    #1258458
    Guma
    Participant

    Yes, thanks for the advice, i will definitelly do the child theme setup after i will find a code which is working.

    Br
    Peter

    #1258542
    Nico
    Moderator

    Let us know how it goes.

    Thanks. Feel free to ask us again.

    #1258954
    Guma
    Participant

    Hello,
    well, the codes for moving the js to the footer provided by you are not working. 🙂
    Was hoping that i will get the solution here 🙂
    The codes are pretty much the same as i find on internet.
    So i guess its a standart code widely used across the wp world, so i am wondering why its not working for me.

    Peter

    #1259152
    Paul R
    Moderator

    Hi Peter,

    I can see you have wp rocket plugin installed.

    Can you try testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

  • <script> jQuery(function($){ $("#no-reply-1256808 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>