[Resolved] The Last Update Date on Some Post Does not Show on Google Search

Home Forums Support [Resolved] The Last Update Date on Some Post Does not Show on Google Search

Home Forums Support The Last Update Date on Some Post Does not Show on Google Search

  • This topic has 9 replies, 2 voices, and was last updated 5 years ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #853908
    Willya

    Hi,

    So, I use the code that David created for me on this post to show entry meta with gravatar, last update and comment.

    The last update show correct on all of my post.

    But, the problem is on some of my post, the last udpate date is does not show on Google search, while the others post is show last update correctly on Google search.

    I include for example my post url on the form, so that Admin can check it.

    I just cant relax because of this problem.

    I have try Clear the cache and forced Google to fetch it on Google Search Console.

    But it seems not work

    I think I need to remove date published from the code. Please help me..

    #853975
    Willya

    Same problem with this thread: https://generatepress.com/forums/topic/how-to-show-updated-posts-with-plugin/

    Is the code Tom created on this post is still works?

    #854390
    Tom
    Lead Developer
    Lead Developer

    That won’t work if you’re already using the function David gave you.

    You could try something like this:

    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() )
    		)
    	);
    	
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
    	}
    	
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	printf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    
    	if ( ! 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>';
    	}
    
    }

    However, it’s up to Google whether to show the date or not for a specific article.

    #854724
    Willya

    Thank you, Tom. This is works!

    #854743
    Willya

    Hi Tom, I want to remove avatar photo. So, the entry meta just show: Author name, last updated and comments count.

    How to do that in the code above?

    Thanks for your super support anyway πŸ™‚

    #854897
    Tom
    Lead Developer
    Lead Developer

    I just edited the code to remove the avatar πŸ™‚

    #856404
    Willya

    Hi Tom. I am sorry I change my mind. Could you edit once again the code above to just show only “author name (with no avatar) and last updated date”. So, no comments count on the entry meta.

    #857047
    Tom
    Lead Developer
    Lead Developer

    Here you go:

    add_filter( 'generate_post_author', '__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() )
    		)
    	);
    	
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
    	}
    	
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	printf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    
    }
    #857487
    Willya

    Thank you Tom! Glad to be part of GP family. The support here is awesome!

    #858480
    Tom
    Lead Developer
    Lead Developer

    You’re welcome! We’re happy to have you πŸ™‚

    Thanks!

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