kaiseki / wp-dequeue-assets
Conditionally dequeue and deregister WordPress scripts and styles using context filters
Requires
- php: ^8.2
- kaiseki/config: ^2.0
- kaiseki/wp-context: ^1.0
- kaiseki/wp-hook: ^2.0
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- bnf/phpstan-psr-container: ^1.1
- kaiseki/php-coding-standard: ^1.0
- maglnet/composer-require-checker: ^4.0
- php-stubs/wordpress-stubs: ^6.2
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.0
- roave/security-advisories: dev-latest
- roots/wordpress-core-installer: *
- roots/wordpress-no-content: @stable
- szepeviktor/phpstan-wordpress: ^2.0
- thecodingmachine/phpstan-safe-rule: ^1.4
This package is auto-updated.
Last update: 2026-06-02 23:44:14 UTC
README
Conditionally dequeue and deregister WordPress scripts and styles using context filters.
A kaiseki/wp-hook HookProviderInterface wired through ConfigProvider: list the script/style
handles you want gone and, optionally, the condition under which to remove them. A condition is either
true (always, on the front end) or a kaiseki/wp-context ContextFilterInterface — given as an
instance, a class-string resolved from the container, or a list of filters combined into a
ContextFilterPipeline — so you can scope removal to specific templates, post types, etc.
Installation
composer require kaiseki/wp-dequeue-assets
Requires PHP 8.2 or newer.
Usage
Register ConfigProvider with your laminas-style config aggregator and configure the
dequeue_assets key:
use Kaiseki\WordPress\DequeueAssets\DequeueAssets; return [ 'dequeue_assets' => [ 'scripts' => [ // handle => true (always) | ContextFilter class-string | list of filters 'wp-embed' => true, 'comment-reply' => true, 'some-plugin-script' => IsFrontPage::class, ], 'styles' => [ 'wp-block-library' => true, ], ], 'hook' => [ 'provider' => [ DequeueAssets::class, ], ], ];
ConfigProvider registers DequeueAssetsFactory, which reads the dequeue_assets config and resolves
each context filter (or list of filters, combined into a ContextFilterPipeline) from the container.
Removal runs on wp_enqueue_scripts and wp_footer (priority 999) and is skipped in the admin.
Development
composer install
composer check # check-deps, cs-check, phpstan
License
MIT — see LICENSE.