AI Verified

Name

Remove Unused Javascript

About

Remove Unused Javascript - and improve your Page Speed Insight Score

Language

Javascript

Rating

Voted: 30 by 32 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:

16/05/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 );

30

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

    2 months ago

    bagus terus di tingkatkan 

Related Snippets

Please see some snippets below related to this snippet..

Performance

AI Verified

2

WP Cache Buster

Added: 1 year ago

Last Updated: 8 months ago

Force design changes to apply to all existing website visitors with browser caching on. Details, code and idea from this post https://www.recolize.com/en/blog/wordpress-cache-busting-design-changes/

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.

Performance

AI Verified

0

Add Custom Image Sizes

Added: 1 year ago

Last Updated: 1 year ago

This snippet allows you to define custom image sizes that can be used throughout your WordPress site.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

30

Remove Unused Javascript

Added: 1 year ago

Last Updated: 1 week 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: 7 months ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 6 months ago

Last Updated: 5 days ago

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