要检查用户是否是管理员,请使用( current_user_can( \'manage_options\' ) )
.
然后,您可以将css文件排队,从而在functions.php
:
add_action ( \'wp_enqueue_scripts\', \'ic_admin_navbar_frontend_css\' );
function ic_admin_navbar_frontend_css() {
if( current_user_can( \'manage_options\' ) && ! is_admin() ) { // we don\'t want to load this on the admin side, just the front end
wp_enqueue_style( \'ic-navbar-fix\', get_stylesheet_directory_uri() . \'/pathtofile/in/templatedirectory/my_special.css\' );
} // end check for admin user on frontend
} // end ic_navbar function
希望这有帮助。
编辑:对不起,我误读了这个问题。。。要检查是否有人登录,请使用is_user_logged_in()
. 只需更换current_user_can()
你应该准备好了。