“The editor has encountered an unexpected error” After add defer tag to java script

Question

I added below script to add defer tag in javascripts. Once it added to function.php
Gets error on create post “The editor has encountered an unexpected error.” I cannot create or edit post.
How can i add defer tag to javascripts without affecting to the editor. I don’t have mush experience in coding. Thanks.

add_filter( 'script_loader_tag', function ( $tag, $handle ) {

    if ( 'jquery-core' !== $handle )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
}, 10, 2 );

console errors are

TypeError: d.media is not a function
wp-includes/js/dist/media-utils.min.js?ver=9ad24b42cc69f241229ded4dc61409fb:2:6432)
wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:63:107) and
more..

0
Chadsmith 4 months 0 Answers 15 views 0

Leave an answer