Seeing as your aim is to improve loading on the front end, the best approach would be to simply not add the defer attribute when loading in the admin area, like so.
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( 'jquery-core' !== $handle ) {
return $tag;
}
if ( ! is_admin() ) {
$tag = str_replace( ' src', ' defer="defer" src', $tag );
}
return $tag;
}, 10, 2 );
As the editor has a number of scripts, often depending on other scripts already loading, it’s generally not a good idea to try and use async or defer in the admin.
Related Posts:
- How to add defer=”defer” tag in plugin javascripts?
- When to use add_action when registering/enqueuing scripts
- WordPress add script with custom type (x-jquery-tmpl)
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- How to include jQuery and JavaScript files correctly?
- How to add a custom CSS class to core blocks in Gutenberg editor?
- force enqueue script to be first in order of prominence
- Why is javascript allowed in my post content?
- How to pass/get data to/from the WooCommerce data-product_variations object?
- How to dequeue a script?
- Move WordPress native javascript to bottom of page?
- RequireJS in custom theme. Working Example
- jQuery in header or footer
- How to get a jQuery script to run on a page?
- AJAX filter posts on click based on category
- Remove left alignment option in core/image block
- Including javascript for a shortcode
- Asynchronous Javascript Loaders
- Use js script from one plugin in another plugin
- Removing labels and tag on WordPress’s default login form
- wp_enqueuescript won’t load in footer even with true value set?
- How wp_enqueue_script works?
- Enqueuing Script in functions.php vs on the page
- How do I get my page to load the jQuery UI Effects library?
- Script won’t execute in the media manager
- How to properly add Bootstrap and JQuery Javascripts?
- How can I filter block registration based on post-type? (Block alignment settings)
- Same Conditionals Not Working on Two Different Hooks
- Including Javascript options
- Enqueuing javascript files
- Problem in loading javascript in footer
- WP_enqueue_script() loads them always in wp_footer()?
- Add attribute to script loaded by the theme
- jQuery not available to other scripts
- Add Defer Attributes to WordPress Scripts with consistent versioning
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- WP Filter to change the URL of an Anchor wrapping the last gallery image
- how to en-queue jQuery to load before the tag
- Searching multiple tags and adding jQuery dependant script onto page template?
- Add Lightbox To WordPress Native Gallery
- should i be checking for jquery before enqueing it in a plugin
- Plugin Scripts no loading on options page
- How to enque js script in footer that are not in .js file?
- Loading scripts on a single page plants the script in the footer
- Run a jquery script on on a certain template page
- How to load jQuery in TOP of wp_footer?
- Include Jquery libraries in wordpress theme?
- Using WP functions inside javascript
- Remove pretty photo style and script if not exist!
- Including Older Version of jQuery for IE7/IE8
- How To Include JavaScript Files Only In Single Posts?
- How do I add tags to entire comments, not just their text
- How to load Javascript code or functions.php later in a child theme?
- Running JavaScript after using WooCommerce Filter Plugin
- how to unescape wordpress output
- How to bridge the gap between dynamic back-end data and front-end output?
- Unable to defer loading of jquery
- How to make JQuery load on top of head tag before everything
- Add Index to Item in WordPress Gallery
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Change add_filter based on Ajax
- JavaScript code do not works on online server
- Bootstrap with separate js File
- How to add JS snippet before closing tag?
- Enqueue javascript that inserts custom php widget into jQuery-constructed div
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- How to Run a jQuery Script after a Javascript Script has Finished in WordPress
- javascript not loading in wordpress
- Theme now uses require.js and enqueue script no longer works
- bootstrap-slider.js by seiyria not working in wordpress
- Uncaught ReferenceError: tippy is not defined
- Limit total tags in the_content
- Why is my JS not working on initial load?
- Insert selection from filter everything pro into gravity forms field
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- Why doesn’t remove_action work in my plugin?
- Using a filter to modify Genesis wp_nav_menu
- Why load JS through the CMS framework? [duplicate]
- How to execute Javascript on a WordPress page?
- Something is filtering my shortcodes… Can’t figure out what
- admin_enqueue_scripts not rending JS file correctly
- Remove actions/filters that are set with create_function()
- jQuery is not defined, working on local server but not online
- Accessing an API with jQuery and AJAX
- Hook in a sidebar widget and add some markup
- return get_the_tag_list with whitespace removed
- Load JavaScript on specific page with @wordpress compiler
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- Modify author url display in edit-comments.php
- Filter Post Title without affecting screen-reader-text
- Hook to change the site URL
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- add_filter not working inside if function
- Masonry – Can’t Find Variable imagesLoaded
- Override typo in multiple parent theme files?
- Element works, but not on wordpress site [duplicate]
- WooCommerce comments_template Filter Not Firing
- Footnotes with dynamic title attributes?
- How do I remove/hide embed excerpts from posts
- How do I query Pending posts?