Site logo

Archived topic

Avatar next to site title?

4 replies · Started by Arp on August 13, 2022

Viewing posts 1–5 of 5

Would I need to create an element for this, or is there a hook/filter option?

Hi there,

where is the Site Title being displayed ? Is it in the regular site header ? If you share a link to the site i can check, and advise which hook(s) to use.

It's on a dev site (details in private info), and I currently have the avatar there as the logo, which I'd like to replace with the avatar so any change in avatar is reflected.

It's in the regular header, where the nav is being used as the header.

Ok, so you can use this filter: generate_navigation_logo

https://docs.generatepress.com/article/generate_navigation_logo/

with the get_avatar_url function:

https://developer.wordpress.org/reference/functions/get_avatar_url/

Which results in a PHP Snippet that you can add to your site:

add_filter( 'generate_navigation_logo','lh_category_navigation_logo' );
function lh_category_navigation_logo( $logo ) {
    $logo = get_avatar_url( 'your_user_email' ,['size' => '80'] ); 

    return $logo;
}

In the get_avatar_url function you will see the first field requires an ID or user email, so the 'your_user_email' needs updating in the function. And set the size in pixels that you need the image to display.

One thing to note - this will require a 3rd party request being made to the gravatar servers which can lead to a delay in that image being first displayed.

Thanks David!

This archived topic is closed to new replies.