# Remove Specific Scripts and Styles by Handle

> Stops chosen plugin or theme scripts and stylesheets from loading on the front end, optionally everywhere except the pages where they are needed.

- Type: PHP
- Runs: Frontend only
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: scripts, styles, performance, dequeue
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dev-dequeue-assets/

## Code

```php
add_action( 'wp_enqueue_scripts', function () {
    // Handles to remove.
    $scripts = array( 'contact-form-7' );
    $styles  = array( 'contact-form-7' );

    // Keep them on these pages (slugs or IDs). Empty = remove everywhere.
    $keep_on = array( 'contact' );

    if ( $keep_on && is_page( $keep_on ) ) {
        return;
    }

    foreach ( $scripts as $handle ) {
        wp_dequeue_script( $handle );
    }

    foreach ( $styles as $handle ) {
        wp_dequeue_style( $handle );
    }
}, 100 );
```

## Notes

Find handles with your browser's view source (the id attribute minus -js or -css) or the "List Enqueued Assets" snippet. Removing a needed file can break features, so test after each change.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Specific Scripts and Styles by Handle" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
