我在 my 中使用以下代码从前端functions.php禁用dashicons.min.css文件。它工作正常,但如何仅对当前未登录 WordPress 的访问者使用该操作?
原因是顶部的 WordPress 管理栏坏了,如果 dashicons css 文件不可用。
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'dashicons' );
}
Run Code Online (Sandbox Code Playgroud)
您想使用is_user_logged_in()WordPress 自带的功能。在https://developer.wordpress.org/reference/functions/is_user_logged_in/阅读它。
所以你的代码是:
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
if( !is_user_logged_in() )
wp_deregister_style( 'dashicons');
}
Run Code Online (Sandbox Code Playgroud)