AI Verified

Name

Remove Unused Javascript

About

Remove Unused Javascript - and improve your Page Speed Insight Score

Language

Javascript

Rating

Voted: 33 by 35 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:

25/07/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 );

33

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

    4 months ago

    bagus terus di tingkatkan 

Related Snippets

Please see some snippets below related to this snippet..

Performance

AI Verified

2

Removes WooCommerce styles and scripts from non WooCommerce pages.

Added: 1 year ago

Last Updated: 3 weeks ago

WooCommerce loads all its JavaScript and CSS files on every single page of your website. Even where they are not needed. This makes your website unnecessarily slow. The following code will help you av...

Performance

AI Verified

4

Remove Gutenberg Block Library CSS from loading on the frontend

Added: 1 year ago

Last Updated: 3 weeks ago

Remove Gutenberg Block Library CSS from loading on the frontend for better perf, if you don't use him

Performance

AI Verified

1

Explicit Fixed Width and Height Images

Added: 1 year ago

Last Updated: 11 months ago

test

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

33

Remove Unused Javascript

Added: 1 year ago

Last Updated: 1 day ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 3 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 2 months ago

This can be used for any WordPress Builder to aid working with CSS Grids.