AI Verified

Name

Remove Unused Javascript

About

Remove Unused Javascript - and improve your Page Speed Insight Score

Language

Javascript

Rating

Voted: 29 by 31 user(s)

How to Setup Snippet

Run everywhere inside Code Snippets

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

27/03/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Remove Unused Javascript

 
                    
1//This has been syncronised 123//
2function wp_remove_scripts() {
3// check if user is admina
4 if (current_user_can( 'update_core' )) {
5 return;
6 }
7 else {
8 // Check for the page you want to target
9 if ( is_page( 'homepage' ) ) {
10 // Remove Scripts
11 wp_dequeue_style( 'jquery-ui-core' );
12 }
13 }
14}
15add_action( 'wp_enqueue_scripts', 'wp_remove_scripts', 99 );

29

Featured Snippet

Comments

  • SH

    1 year ago

    Nice!
  • S

    1 year ago

    Does this check for unused scripts for every page of the website?
  • IS

    1 year ago

    Stav - check this part of the snippet:
    ----------
    if ( is_page( 'homepage' ) ) {
            // Remove Scripts
            wp_dequeue_style( 'jquery-ui-core' );
            }
    --------
    So this one checks only the homepage. You'll have to check for each page separately. 
  • AR

    1 year ago

    Nice - keep on optimising @Web Squadron 😎
  • DS

    1 year ago

    When I have downloaded the snippet, it appears as JavaScript snippet. This is PHP code.
  • JP

    1 year ago

    This only works for non default scripts, but the example is about jquery-ui-core, that is part of Wordpress defaults scripts, the correct addd_action hook in this case would be 'wp_default_scripts' :
    
    
    /**
     * remove unused Wordpress default scripts from frontend
     */
    add_action( 'wp_default_scripts', 'remove_js_ui_library' );
    function remove_js_ui_library( &$scripts){
        if(!is_admin()){
            $scripts->remove( 'jquery-ui-core');
        }
    }
    
  • YO

    1 week ago

    bagus terus di tingkatkan 

Related Snippets

Please see some snippets below related to this snippet..

Performance

AI Verified

0

Remove Google Fonts (Non Elementor)

Added: 10 months ago

Last Updated: 10 months ago

Removed Google Fonts for Non Elementor Websites

Performance

AI Verified

0

Deactivate Specific Plugins on Staging & Non-Production Sites [SnipSnip.pro]

Added: 2 months ago

Last Updated: 2 months ago

This "Deactivate_Plugins_On_Staging" script selectively deactivates specified plugins on your staging and non-production environments based on the site URL. Ideal for disabling plugins that are only n...

Performance

AI Verified

0

Disable Specific Plugins on Production Environments [SnipSnip.pro]

Added: 2 months ago

Last Updated: 2 months ago

<p>Disables the specified plugins on non-production environments (based on the site URL). You can specific which plugins you want deactivated by placing the plugin's slug in the `PLUGINS_TO_DEACTIVATE...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

29

Remove Unused Javascript

Added: 1 year ago

Last Updated: 2 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

9

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 5 months ago

Deactivate some WooCommerce Checkout Fields from showing

Performance

Pro Verified

5

Disable e-icons from Elementor

Added: 1 year ago

Last Updated: 1 year ago

Disable e-icons - and remove the notification from occurring during your Page Speed Insight Check.