Remove WooCommerce Styles and Scripts

Hi-

I added WooCommerce as my shopping cart and now my page loading time is slow. I did a lot of searching for the correct code to prevent WooCommerce from loading pages besides the checkout page. But all the code I tried, failed.

  1. What is the correct code to remove WooCommerce styles and scripts from all pages besides on the pages its needs to be on. ex. checkout, cart or other needed WooCommerce pages?

  2. Where exactly do I put this code?

The is website is: www.candicemcfield.com, http://candicemcfield.com/cart/, https://candicemcfield.com/checkout/

Thanks!

Hi @cmcfield,

I hope you are well today and thank you for your question.

You can try achieving this by using any of the solution posted on the following pages.

https://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/

https://gregrickaby.com/remove-woocommerce-styles-and-scripts/

Best Regards,
Movin

Hi @Movin

I tried the codes and none worked. The errors are below. I added the code to the top of the .php file. Is there a certain spot the codes goes in the .php file? Also, maybe it doesn’t work because the latest WC version is 2.5.5 and the most update code option was WC version 2.4.7. Any other help would be much appreciated as my site (www.candicemcfield.com) is running VERY slow.

Thanks!

Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 6

Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 16

Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 7

The shared error messages say that the function add_action is undefined but it’s defined in the WordPress core as described here add_action() | Function | WordPress Developer Resources

Please make sure you are using latest version of WordPress and tell me which code you are using and where you are adding it in your site.

I am running WP 4.5.2 which is the latest version.

I put the code right underneath the first line >?php So it was >?php on a line. Then I skipped 1 line space. Then on the next line I entered the code.

I attached the .php file (functions.php) I inputed the code into. I pulled it from my server. Which was in the wp-includes folder. There is also a functions.php in WP under Appearance -> Edit Themes -> functions.php. I was under the impression that these two files would be the same rather pulled from my server or directly inside WP. But the code is different. Which one is the correct one to use? I’ve attached both for you. The file inside WP under Appearance is the attached titled functions_InsideWordPress

I tried all the links you recommended:

Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 6

wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/
Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 16

Fatal error: Call to undefined function add_action() in /home/content/56/7411156/html/wp-includes/functions.php on line 7

It seems your second file is not get uploaded due to security reasons so please try compressing it in zip file to share it.

I attached the .php file (functions.php) I inputed the code into. I pulled it from my server. Which was in the wp-includes folder.

It seems you have done it wrong. You should not add custom code in the WordPress core file wp-includes/functions.php but should add it in the functions.php file of child theme of Unite theme by creating it.