Site logo

Archived topic

How to Show Icons before Date and Comments Post Meta

55 replies · Started by Ravi Dixit on July 2, 2019

Viewing posts 31–45 of 56

I don't know why It is showing Leave a Comment there... I am not using anything else except these codes I shared with you.

It is only showing with the post which has no comments.

I sent you temporary admin account's login details.

That link is coming from this Code Snippet: Meta Style Customization

You can find it in the "Snippets" area of your Dashboard.

Okay so now what to do?

If you disable that Snippet, the Leave a comment text should go away.

After removing that snippet, Author gravatar and name is not showing on a single post and also in the search result.

Ok, so we need that snippet, but we need to tweak the PHP.

Can you share the PHP from the snippet in here? Then I'll tweak it and you can replace it.

​Here it is:

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;
}

Try this instead:

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' ) )
		)
	);

	echo $date;
}

Hey, Tom!

It is working but the author name and gravatar is at the end, See this image https://prntscr.com/omqftj

And space should be the same as like between first two meta.

One more thing, How Can I align all meta in one single line on mobile view as I did in single posts.

Try adding this:

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'author',
        'date'
    );
} );

Hi tom

I have added the above code but still no change...

Instead of the function you're using right now to add the gravatar, try this:

add_filter( 'generate_post_author_output', function() {
    return sprintf( ' <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' ) )
        )
    );
} );

It is working the same as the previous code I was using.

Here you can see: https://prnt.sc/onjsge

I want to move Author image and name at the first, and same space between all meta.

This archived topic is closed to new replies.