我不清楚您是否要为用户“editor”隐藏“editor”角色为的用户的“author”框。
以下代码用于检测用户是否具有编辑器角色,并显示所有其他角色的作者框:
// Add this in you single post template
// See https://developer.wordpress.org/themes/basics/template-hierarchy/
// First we get the author role:
global $authordata; // The author object for the current post. See https://codex.wordpress.org/Global_Variables
$author_roles = $authordata->roles; // Get all author roles. See https://codex.wordpress.org/Class_Reference/WP_User
$author_role = array_shift( $author_roles ); // Get the user role
// Now we check if the author is an editor
if ( $author_role != \'editor\' ) {
// Show the author box
}
如果您想隐藏特定“编辑器”用户的“作者”框,请使用以下选项:
// Add this in you single post template
// See https://developer.wordpress.org/themes/basics/template-hierarchy/
// First we get the author username:
global $authordata; // The author object for the current post. See https://codex.wordpress.org/Global_Variables
$username = $authordata->user_login; // Get the author username. See https://codex.wordpress.org/Class_Reference/WP_User
// Now we check if the author username is \'Editor\'
if ( $username != \'Editor\' ) {
// Show the author box
}
如果你觉得这个有用,请告诉我。