Use code PERFMATTERS for an extra 10% off!

How to disable or enable scripts with Regex

You can disable or enable scripts in the Perfmatters Script Manager using Regex (regular expressions). This is especially helpful for sites that have a more complex URL structure in place or dynamically generated pages (archives, search, etc.).

How to use Regex

If you aren’t familiar with Regex, we recommend utilizing this online tool: Kinsta also has some great examples of how to use Regex.

Disable scripts using Regex

Let’s say for example you wanted to disable scripts across your category URLs, but nowhere else. In this case, you could use a regular expression for the category URL. With regular expressions, there are multiple ways you can write them, here are a few variations that would work.

Note: When using Regex as a disable, you should only use Regex for that particular script. Not a combination of Regex and “Current URL.”

Variation 1

This disables the script whenever the URL contains the word category.

Disable script with Regex
Disable script with Regex

Variation 2

This disables the script whenever the URL contains /category/.


You could target multiple categories like this.


Variation 3

This disables the script whenever the URL contains


Variation 4

The following is an exact match, where $ marks the end of the line. Use case example: Your WooCommerce products have /shop/ in the permalink and you only want to disable a script on your shop archive page.


Variation 5

The following matches custom post types as well as ecommerce pages. Use case example: You have an LMS with multiple custom post types, such as courses, lessons, etc. You want to match any child pages underneath those, as well as the /checkout/ and /cart/ pages.


Variation 6

The following could be used to target a script that appears on a dynamically generated WordPress search results page.


You could use that either to disable a script by that regex pattern, or you could use it to enable a script by that regex pattern that has already been disabled everywhere.

Enable scripts using Regex

You can also use Regex as an exception when disabling the script everywhere.

Enable script with Regex
Enable script with Regex

Perhaps you have a plugin that you want to disable everywhere, but you need it to run on two pages.


If you have any questions about Regex or the proper syntax, feel free to contact us for help.

Was this article helpful?

Related Articles