How to remove an enqueued script that I can't find on any of my pages from functions.php? / How to edit functions.php?

can you explain what it was (just in case I might make the same mistake in the future!) thanks :slight_smile:

I highly doubt anyone will do that, but here it is: I’ve been testing some JS scripts and for some reason this one script I was testing on my 404 page. When I was searching for this script throughout the site, I somehow missed this one page. I’m still not sure why it was enqueued in functions.php, but I just deleted the code from 404 page and all is good now.

1 Like

cool - thanks for explaining - you never know when someone (like me) might make the exact same strange mistake - I have a habit of making such strange mistakes myself haha. Thanks again

@Adryan I have to admit that in this type of investigation, it was more convenient for me to review your files from the comfort of the desktop application. Glad I could help you.

For the rest, a good way to clearly define your document is to use the site content action to define by yourself what should be included as the main content of the template and what should be left to the master page. (for the scripts for example)

This way, you will not forget what’s in the header/footer of your documents (as the master page will prevail) and even if you fail, forgotten scripts added outside of the site content of any template using the master page will not be added to the functions.php file during the export.

On this topic, here is an interesting read:

2 Likes

I just wanted to call out the reason behind why it was enqueued.

Inline scripts are automatically enqueued. For eg,

<script>
console.log(''foo")
</script>

When exporting the theme/plugin, the functions.php will include the above script tag like this (automatically):

    wp_register_script( 'inline-script-1', '', [], '1.0.6', false );
    wp_enqueue_script( 'inline-script-1' );
    wp_add_inline_script( 'inline-script-1', 'console.log(\'foo\')');

When the script tag is removed, the same is removed off functions.php (automatically).

1 Like

Indeed @TechAkayy, thank you for that final clarification.

As a matter of fact, we have documentation on this topic:

3 Likes