Site logo

[Resolved] Change avatar size on author page

Home Forums Support [Resolved] Change avatar size on author page

Home Forums Support Change avatar size on author page

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1539055
    Fabien

    Hi,

    Is there a way to change the avatar size in the author page ?

    Thanks,

    Fabien

    #1539189
    Leo
    Staff
    Customer Support

    Hi there,

    Any chance you can link us to the page in question?

    You can use the private information field.

    Let me know 🙂

    #1540205
    Fabien

    Here you go !

    #1540213
    David
    Staff
    Customer Support

    Hi there,

    Try this CSS:

    .archive.author .avatar {
        border-radius: 50%;
        height: 80px;
        width: 80px;
    }
    #1540217
    Fabien

    Thanks but the quality is not so good as the image is loaded in 50px due the following function :

    	function generate_filter_the_archive_title( $title ) {
    		if ( is_category() ) {
    			$title = single_cat_title( '', false );
    		} elseif ( is_tag() ) {
    			$title = single_tag_title( '', false );
    		} elseif ( is_author() ) {
    			/*
    			 * Queue the first post, that way we know
    			 * what author we're dealing with (if that is the case).
    			 */
    			the_post();
    
    			$title = sprintf(
    				'%1$s<span class="vcard">%2$s</span>',
    				get_avatar( get_the_author_meta( 'ID' ), 50 ),
    				get_the_author()
    			);
    
    			/*
    			 * Since we called the_post() above, we need to
    			 * rewind the loop back to the beginning that way
    			 * we can run the loop properly, in full.
    			 */
    			rewind_posts();
    		}
    
    		return $title;
    
    	}

    Isn’t is a filter in order to change the loaded size ?

    #1540219
    David
    Staff
    Customer Support

    This line in the filter:

    get_avatar( get_the_author_meta( 'ID' ), 50 )

    Change the 50 to whatever size in pixels you require.

    #1540229
    Fabien

    Yes, but it means I have to edit core templates right ?

    #1540351
    Leo
    Staff
    Customer Support

    You can use the get_the_archive_title filter with a PHP snippet like this:

    function lh_filter_the_archive_title_increase_author_image_size( $title ) {
        if ( is_category() ) {
    			$title = single_cat_title( '', false );
    		} elseif ( is_tag() ) {
    			$title = single_tag_title( '', false );
    		} elseif ( is_author() ) {
    			the_post();
    
    			$title = sprintf(
    				'%1$s<span class="vcard">%2$s</span>',
    				get_avatar( get_the_author_meta( 'ID' ), 100 ),
    				get_the_author()
    			);
    
    			rewind_posts();
    		}
    
    		return $title;
    }
    
    add_filter( 'get_the_archive_title', 'lh_filter_the_archive_title_increase_author_image_size', 50);

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1540406
    Fabien

    Thanks Leo, works like a charm !

    #1540412
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.