Dequeue Custom Javascript from Pro Builder

Hi Themeco,

Using a child theme, and have enqueued scripts excluding admin, using !is_admin
https://codex.wordpress.org/Function_Reference/is_admin
This works correctly and the scripts are included only the theme frontend, not on Wordpress admin.

However the scripts are still getting enqueued on all of the Pro builders (Header, Footer, Content, Global Block)

I’m using custom javascript to modify the scroll behaviour, this work correctly on the frontend theme. However, I do not want these javascript enqueued on any or Pro Builders as the modified scroll behaviour stops the builders from working. !is_admin works prefectly, however I cannot exclude the enqueue or dequeue load the scripts on the Pro Builders.

I tried using the url to exclude following https://kinsta.com/blog/disable-wordpress-plugins-loading/ using

Enqueue

function my_scripts() {
  $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
  $is_pro = strpos( $request_uri, '/pro/' );
  if ( ! is_admin() ) {
    if ( $is_pro === false) {
      wp_enqueue_script('my_bundle_js', get_stylesheet_directory_uri() . '/dist/js/my-bundle.js', null, X_VERSION, true);
    }
  }
}
add_action('wp_enqueue_scripts', 'my_scripts');

Dequeue

function my_dequeue_scripts_pro() {
  $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
  $is_pro = strpos( $request_uri, '/pro/' );
  if ( $is_pro !== false ) {
    wp_dequeue_script( 'my_bundle_js' );
    wp_deregister_script( 'my_bundle_js' );
  }
}
add_action( 'wp_print_scripts', 'my_dequeue_scripts_pro', 100 );

However, because the Pro Content builder loads the page in a iframe this url method to exclude enqueue or dequeue scripts does not work.

What is the Pro equivalent of !is_admin or how can I exclude enqueue or dequeue scripts from all of the Pro Builders?

Hi @strobley,

I am afraid that this will be a customization that is not possible. The problem is exactly what you have described. The !is_admin is the correct way to handle that. That is why the Javascript code is not added in the Pro Builder environment, but the problem is that the Pro builder uses iFrame to have the Preview window, and that preview window is the frontend! So as you added the Javascript for the front end, it will be loaded inside the iFrame preview.

You see the problem? I don’t think you will be able to get around that one, unfortunately, and that is s nature of front ends page builders such as the Pro builder and any other builder that has a front end preview.

So this is not a matter of having specific code for Pro instead of is_admin. Pro does not have such a code, but if it had had the code like that, the preview would load the script anyway.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.