[英]WordPress: Gutenberg not loading when Defer Parsing of JavaScript added in functions.php
I'm trying to incorporate a Defer Parsing of JavaScript function into my functions.php file.我正在尝试将 JavaScript 函数的延迟解析合并到我的 functions.php 文件中。 When I do, the site still works fine, but in wp-admin, anything involving Gutenberg wont' load and I just get the white screen of death.
当我这样做时,该站点仍然可以正常工作,但是在 wp-admin 中,任何涉及 Gutenberg 的内容都不会加载,我只会得到白屏死机。 Any idea if this code is bad?
知道这段代码是否不好吗?
// Defer Parsing of Javascript
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
The page where you probably downloaded this code has a comment in it that solved it.您可能下载此代码的页面中包含解决该问题的注释。 Use this instead:
改用这个:
function defer_parsing_of_js( $url ) {
if ( is_user_logged_in() ) return $url; //don't break WP Admin
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
Source: https://kinsta.com/blog/defer-parsing-of-javascript/ (Answer by Dean)来源: https ://kinsta.com/blog/defer-parsing-of-javascript/(Dean 回答)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.