I’m using Flatsome theme.
I want to change the logo based on the user role of the current user.
In the flatsome-child folder I’ve accessed the functions.php.
Just trying to change the logo isn’t working, so I’ve tried with some code, giving me nada change.
I’ve googled on how to change custom logo, but all I find is how you can change it in WordPress, but I need to have two different logos based on user role.
<?
add_filter('get_custom_logo', 'helpwp_custom_logo_output', 10);
function helpwp_custom_logo_output() {
$html = '<a href="https://www.linkhere.com/" title="linkhere.com" rel="home">';
$html .= '<img width="278" height="73" src="https://www.linkhere.com/wp-content/uploads/2019/11/linkhere-logo-custom.png" class="header_logo header-logo" alt="linkhere" scale="0">';
$html .= '<img width="278" height="73" src="https://www.linkhere.com/wp-content/uploads/2019/11/linkhere-logo-custom.png" class="header-logo-dark" alt="linkhere" scale="0">';
$html .= '</a>';
$html = str_replace('header_logo', 'logo', $html );
return $html;
}
?>
2
Answers
WordPress stores user roles as capabilities in the user meta table. You can format your page templates like so:
Give custom path of your logo image above
WordPress has a function called
https://developer.wordpress.org/reference/functions/current_user_can/
It returns TRUE or FALSE.
The capabilities are:
‘delete_user’, ‘edit_user’, ‘remove_user’, ‘promote_user’, ‘delete_post’, ‘delete_page’, ‘edit_post’, ‘edit_page’, ‘read_post’, or ‘read_page’
User roles are supported in part, like ‘administrator’ or ‘editor’.
With this function you can do something like this:
Regards Tom