Hi renteriah,
that’s surely possible. You didn’t mention what information you’d like to have displayed, that’s why I assume that you want the default title to be visible by all and the secondary title only visible for certain roles.
To achieve that, simply adjust this script and add it to your functions.php:
/**
* @param $secondary_title
*
* @return bool|string
*/
function show_secondary_title_by_role($secondary_title) {
/** Here, we define the allowed role IDs */
$allowed_roles = array(
"administrator"
);
/** Get information about the currently logged-in user */
$current_user = new WP_User(get_current_user_id());
/** Default value */
$is_allowed = false;
/** Go through our allowed roles */
foreach($allowed_roles as $allowed_role) {
/** Check if role is part of user's role(s) */
if(in_array($allowed_role, $current_user->roles, true)) {
/** If yes, we got what we need and can cancel the loop */
$is_allowed = true;
break;
}
}
if($is_allowed) {
/** All good, you're allowed to view the secondary title */
return (string)$secondary_title;
}
/** Not authorised; display nothing */
return false;
}
add_filter("get_secondary_title", "show_secondary_title_by_role");
If you found this helpful, I’d very happy if you could leave a quick plugin review.