Site logo

Archived topic

Change avatar size on author page

9 replies · Started by Fabien on November 20, 2020

Viewing posts 1–10 of 10

Hi,

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

Thanks,

Fabien

Hi there,

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

You can use the private information field.

Let me know :)

Here you go !

Hi there,

Try this CSS:

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

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 ?

This line in the filter:

get_avatar( get_the_author_meta( 'ID' ), 50 )

Change the 50 to whatever size in pixels you require.

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

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/

Thanks Leo, works like a charm !

No problem :)

This archived topic is closed to new replies.