Site logo

Archived topic

Remove Gravatar From Entry Meta PHP

7 replies · Started by Zad on August 20, 2018

Viewing posts 1–8 of 8

I currently use the following customized PHP code (by Tom) to insert a Gravatar Entry Meta into my single blog posts, however, the gravatar itself is not necessary for my blog and when reaching the page reaches for the gravatar, it seems to slow down by site. So, while I want the format still to be Author | Updated Date, I don't want the gravatar to be next to the author.

Here's what the current PHP code looks like for this function (entry meta)

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() ),
			get_avatar( get_the_author_meta( 'ID' ) )
		)
	);

	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}

	echo $date;
}

Here's the accompany CSS being used for styling the entry meta,

.byline img {
    width: 0px;
    height: 0px;
    border-radius: 50%;
    position: relative;
    vertical-align: middle;
    margin: 0 0px 0 0;
}

.byline,
.comments-link,
.posted-on {
	display: inline-block;
}

.comments-link,
.posted-on {
	border-left: 1px solid #ddd;
	padding-left: 10px;
	margin-left: 10px;
}

.comments-link:before {
	display: none;
}

h2.entry-title {
    margin-bottom: 20px;
}

And the date CSS being used on my blog to change "post date" to "updated date"

.posted-on .updated {
    display: inline-block;
}

.posted-on .updated + .entry-date {
    display: none;
}

.posted-on .updated:before {
    content: "";
}

Along with PHP function to produce Estimated reading time,

function tu_estimated_reading_time() {
    $post = get_post();
    $content = $post->post_content;
    $wpm = 300; // How many words per minute.

    $clean_content = strip_shortcodes( $content );
    $clean_content = strip_tags( $clean_content );
    $word_count = str_word_count( $clean_content );
    $time = ceil( $word_count / $wpm );

    return $time . ' minutes';
}

add_filter( 'generate_post_date_output', function( $output ) {
    $output .= '<div class="read-time">Read time: ' . tu_estimated_reading_time() . '</div>';

    return $output;
} );

Sorry for all this code, I just posted the relvant code that may be intertwined with one another and that may interfere with one another when making edits.

Again, I want to remove the gravatar from the Entry meta, but keep the formatting of where the author is and where the date is so: Author | Updated Date

What it currently looks like, and what I want to keep it as. I simply want to prevent the function from retrieving the Gravatar image for the entry meta

https://imgur.com/a/AAvTB2i

Hi there,

try this snippet:

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() )
		)
	);

	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}

	echo $date;
}

It worked! Thank you 🙂. Would the styling CSS be the same? I know there's some CSS code for adjusting the gravatar image, but since there no longer needs to be a gravatar image, how would the CSS look?

You can remove the first CSS Rule and its properties ie.

.byline img {
    width: 0px;
    height: 0px;
    border-radius: 50%;
    position: relative;
    vertical-align: middle;
    margin: 0 0px 0 0;
}

Thank you!

You're welcome

This archived topic is closed to new replies.