skip to Main Content

I am trying to stop a script from loading in HTML on my WordPress website.
In my HTML file I can see these two scripts:

<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www.[-----------].se/wp-content/plugins/theme-my-login/assets/scripts/theme-my-login.min.js?ver=7.1.2' id='theme-my-login-js'></script>

<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www. [-----------].se/wp-content/themes/guru/framework/js/public/jquery.smartresize.js?ver=5.5.2' id='jquery-smartresize-js'></script>

In public_html/wp-content/themes/guru/framework/register_public.php I can comment out the second script and prevent it from loading to HTML by setting /* */ in the above php file:

/* wp_enqueue_script('jquery-smartresize', $template_uri.'/js/public/jquery.smartresize.js', array(), false, true); */

The first script comes from a plugin that I want to use on a certain page, so I do not want to deactivate the plugin. I will build a IF-statement in the php file to exclude/include the plugin script from loading into HTML based on page URL.

My problem is that I cannot find the php file that loads the first script to HTML, like I found for the second script. I do not find anything interesting or get to many hits when searching via ssh in public_html. Can I ad a filter? How would the code for the filter be? I guess it is better to prevent the wp_enqueue_script from excecuting than to have wp_enqueue_script and then add a filter.

2

Answers


  1. Chosen as BEST ANSWER

    Actually I only used

    if ( isset( $_SERVER['REQUEST_URI'] ) &&
    strpos( $_SERVER['REQUEST_URI'], 'the/page/that/uses/the/scripts' ) === false ) 
    {wp_dequeue_script( 'theme-my-login' );
    }
    

    I did not call on the function SO_21097900...that did not work...I do not know where to put the function. If I put the function in the same php file then my website goes down.


  2. Yeah you can dequeue the scripts where they’re not needed

    
    function SO_21097900() {
        wp_dequeue_script( 'theme-my-login' );
        wp_dequeue_script( 'jquery-smartresize' );
    }
    
    if ( isset( $_SERVER['REQUEST_URI'] ) &&
     strpos( $_SERVER['REQUEST_URI'], 'the/page/that/uses/the/scripts' ) === false ) {
        add_action( 'wp_enqueue_scrips', 'SO_21097900', 100 );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search