Prevent scripts to run in the Breakdance editor

Opening Breakdance is like opening the website in the frontend!

Which means that all third-party scripts will also run inside Breakdance.

Why it can be an issue?

Let's say that we need to add the tracking code from our favorite analytics solution.

The easiest way is to insert it in the Header or Footer code block from the Breakdance Custom Code page:

The main problem is that this script will also run when we open Breakdance. Ideally, we only want the code to run in the frontend. Or it can messed up our statistics.

Using a snippet manager

A snippet manager like WPCodeBox (aff link) will give you more options, like where to run the scripts. But once again, even if we choose to run it only in the frontend, it will still run inside Breakdance.

What to do then?

The solution is to add a PHP condition :


Which we can insert in the condition builder of WPCodeBox. We just have to select Custom PHP Condition and paste the code. (note that most Snippet Managers have a similar feature)

Now our script will finally run only in the frontend, for our visitors. We won't affect the stats each time we open Breakdance.