admin管理员组文章数量:1290176
WordPress loads jQuery.migrate automatically:
How can I disable it without plugins? I didn't find code in functions.php with enqueue
.
It loads from /wp-includes
. How can I disable it?
WordPress loads jQuery.migrate automatically:
How can I disable it without plugins? I didn't find code in functions.php with enqueue
.
It loads from /wp-includes
. How can I disable it?
- Very bad idea. WordPress core needs jQuery. – Frank P. Walentynowicz Commented Jan 21, 2018 at 10:48
- on which page do you want to disable jQuery ? – mmm Commented Jan 21, 2018 at 10:49
- 2 @FrankP.Walentynowicz jQuery Migrate is not the whole of jQuery. It's a migration script that's not nested most times. – swissspidy Commented Jan 21, 2018 at 14:36
2 Answers
Reset to default 26jQuery Migrate is nothing but a dependency of the jQuery script in WordPress, so one can simply remove that dependency.
The code for that is pretty straightforward:
function dequeue_jquery_migrate( $scripts ) {
if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff(
$scripts->registered['jquery']->deps,
[ 'jquery-migrate' ]
);
}
}
add_action( 'wp_default_scripts', 'dequeue_jquery_migrate' );
This will prevent the jQuery Migrate script from being loaded on the front end while keeping the jQuery script itself intact. It's still being loaded in the admin to not break anything there.
In case you don't want to put this in your own plugin or theme, you can use a plugin like jQuery Light that does this for you.
Wordpress supports "deregistering" a plugin, using a similar process as mentioned by @swissspidy, but with less code.
In whatever function you're enqueuing your plugins, add this line:
wp_deregister_script('jquery-migrate');
This assumes that jQuery Migrate is enqueued with the handle jquery-migrate
, which is its Wordpress default.
So here's an example of my Enqueue function with WP action:
function my_theme_enqueue_styles_and_scripts() {
wp_enqueue_style('my-theme-styles', 'dist/styles.css');
wp_deregister_script('jquery-migrate');
wp_enqueue_script('my-theme-scripts', 'dist/scripts.js');
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles_and_scripts', 99);
本文标签: phpHow to stop jQuerymigrate manually
版权声明:本文标题:php - How to stop jQuery.migrate manually 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741495272a2381808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论