Trying to deque some .js from source

that is my source: view-source:buhehe.de i am trying to deque some script form function.php i mean these two:

script type="text/javascript" src="http://buhehe.de/wp-content/themes/tema/js/jquery-3.2.1.min.js"/script
script type='text/javascript' src='http://buhehe.de/wp-includes/js/jquery/jquery.js?ver=1.12.4'/script

I added following code in Function.php but it doesn't deques scripts from source:

function dequeue_script() {
   wp_dequeue_script( 'http://buhehe.de/wp-content/themes/heatt/js/small-menu.js?ver=4.9.1' );
   wp_dequeue_script( 'http://buhehe.de/wp-includes/js/wp-embed.min.js?ver=4.9.1' );
      wp_dequeue_script( 'http://buhehe.de/wp-includes/js/wp-embed.min.js' );
}
add_action( 'wp_print_scripts', 'dequeue_script', 100 ); 

How can i deque these scripts fcrom source?

Topic Wordpress javascript

Category Web


You could try using the script_loader_tag filter. If they are enqueued properly this should get rid of them based on the URLs you provide:

add_filter('script_loader_tag', 'custom_remove_scripts', 11, 2);
function custom_remove_scripts($link, $handle) {
    $urls = array(
         'http://buhehe.de/wp-content/themes/heatt/js/small-menu.js',
         'http://buhehe.de/wp-includes/js/wp-embed.min.js'
    );
    foreach ($urls as $url) {
        if (strstr($link, $url)) {$link = '';}
    }
    return $link;
}

Otherwise as already stated by others you would need to find where the links are hardcoded in your theme. If you find they are enqueued using wp_enqueue_script then you can remove them using wp_dequeue_script by their script handle not by their URL as in your code.


Try using wp_enqueue_scripts with the handle like this example in your functions.php file :

add_action( 'wp_enqueue_scripts', 'remove_scripts', 100 );
function remove_scripts() {

    wp_dequeue_script( 'original-handle' );
    wp_deregister_script( 'original-handle );

}

However, this will only work if they have been loaded correctly in using wp_enqueue_scripts. Looks like they have been hard coded in a file which isn't best practice in WordPress.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.