Tagged: x
-
AuthorPosts
-
November 14, 2016 at 12:47 pm #1256808
GumaParticipantHello, 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
PeterNovember 14, 2016 at 12:48 pm #1256813
GumaParticipantThis reply has been marked as private.November 14, 2016 at 5:28 pm #1257110
JadeModeratorHi there,
You might want to check out this plugin: https://wordpress.org/plugins/scripts-to-footerphp/
Hope this helps.
November 15, 2016 at 12:03 am #1257521
GumaParticipantHello, 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.
ThxNovember 15, 2016 at 4:03 am #1257688
ThaiModeratorHi 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 🙂
November 15, 2016 at 9:16 am #1258020
GumaParticipantHello, 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
November 15, 2016 at 12:28 pm #1258313
Nabeel AModeratorHi 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!
November 15, 2016 at 3:15 pm #1258458
GumaParticipantYes, thanks for the advice, i will definitelly do the child theme setup after i will find a code which is working.
Br
PeterNovember 15, 2016 at 4:38 pm #1258542
NicoModeratorLet us know how it goes.
Thanks. Feel free to ask us again.
November 15, 2016 at 11:12 pm #1258954
GumaParticipantHello,
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
November 16, 2016 at 4:06 am #1259152
Paul RModeratorHi 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.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1256808 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
