1

firstly please pardon my complete ignorance in regards to Wordpress and Web Development in general if in being completely honest.

I have a theme on my website which came with a whole bunch of Javascript addons (like pretty photo) that i dont want. There are literally tons of them. Now, i want to remove the relevant files altogether, but that will result in 404 on those files (which wont help with my load times).

My question, i have been reading an aweful lot about wp_dequeue_script , and how it removes files. Why not just delete the actual wp_enqueue_ files from function.php??

Does that cause problems? Any insight into the matter would be much appreciated.

Anoop Asok
  • 1,311
  • 1
  • 8
  • 20
Huzi
  • 21
  • 3

1 Answers1

2

Welcome to the world of Wordpress.

Why not just delete the actual wp_enqueue_ files from function.php??

The only answer and explanation to this question is, if you are not the author of a plugin or theme, never make any type of modification to that plugin or theme. This also goes for Wordpress core files. The simple reason being, if you ever upgrade your theme/plugin/core, all your changes will be lost and cannot be retrieved. This is a very costly mistake

The proper way

In your case, you should use functions like wp_deregister_script() and wp_dequeue_script() to remove scripts you don't need. See this post on how to correctly remove scripts.

This functions should go in either a custom plugin or a child theme. This should never go into the theme directly as this will be deleted when you update your theme.

I hope this helps

Community
  • 1
  • 1
Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55
  • 1
    In my case wp_dequeue_script or wp_dequeue_style has no effect. The scripts or styles are included non the less. Is this due to an ill behaving plugin/theme or a design flaw in wordpress. I spend 4 hours to remove a script from the queue but is still is showing up. The culprtt is https://wordpress.org/themes/activello/ – theking2 Sep 24 '21 at 19:59