Home  >  Q&A  >  body text

Stop requesting script loading in HTML file

I'm trying to prevent scripts from loading as HTML on my WordPress site. 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/script/theme-my-login.min.js?ver=7.1.2' id='theme-my-login-js'></script>

<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www.phpcnc.com [---------------------].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 set it in the above php /* */ to prevent it from being loaded into the HTML file:

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

The first script is from a plugin that I want to use on a certain page, so I don't want to deactivate the plugin. I will be building an IF statement in the php file to exclude/include the plugin script from being loaded into the HTML based on the page URL.

My problem is that I can't find the php file that loads the first script into HTML, like I can for the second script. Searching via ssh in public_html I didn't find anything interesting or get many clicks. Can I add filter ads? What does the filter code look like? I guess it would be better to prevent wp_enqueue_script from executing rather than letting wp_enqueue_script then add a filter.

P粉154798196P粉154798196175 days ago343

reply all(2)I'll reply

  • P粉691958181

    P粉6919581812024-04-01 12:36:37

    Actually, I have 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'm not calling the function SO_21097900...this doesn't work...I don't know where to put the function. If I put that function in the same php file, my site crashes.

    reply
    0
  • P粉734486718

    P粉7344867182024-04-01 09:16:46

    Yes, you can dequeue scripts where you don't need to

    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 );
    }
    

    reply
    0
  • Cancelreply