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?
- WordPress REST API and Backbone JS
- Modify Gutenberg blocks quick inserter defaults
- How do I ensure that the URL parameters are updated correctly when multiple filters are applied
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- Jquery function working in Dev Console but not otherwise [duplicate]
- the_content filter together with require_once returns 1 instead of the content of the included file
- How can I replace an oEmbed URL in post with actual embed HTML
- How to enqueue jquery in admin and why is it not already there?
- Woocommerce “added to cart” message on main(home) page
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- Why doesn’t remove_action work in my plugin?
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- Missing Argument 2 for apply_filter
- Create shortcode to echo javascript
- How to check if a protected hook is hooked?
- Call a javascript function from another file
- Modify Redux Framework Options in Child Theme
- Enque Javascript in Footer?
- Using a filter to modify Genesis wp_nav_menu
- Why does adding a filter to ‘the_title’ break the server?
- How to get a single hook from wp_head()?
- WP filter to alter admin CSS styles?
- How do I Import / Upload Files with jQuery AJAX?
- Plugins loading multiple copies of JQuery
- Redirect to another page using contact form 7? [closed]
- Why is my WordPress loading old version of JQuery?
- Filter Hook callback error, is it due to using $this inside a filter or something else?