[Resolved] How to show updated posts with plugin

Home Forums Support [Resolved] How to show updated posts with plugin

Home Forums Support How to show updated posts with plugin

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #825433
    Swadhin

    Hi Tom,

    I am facing a serious issue where Google is not picking up “last updated” date and time and showing published ones. I tried various codes (one Brian from woorkup uses, and ones I was provided within the GP forum).

    At last, I need to resort to an external plugin (so that some posts like coupons that are very critical on date for CTR in search) would not lose rankings (they are losing rankings now).

    I want to use the plugin “Last Modified Info plugin” as mentioned in this post on authority hacker.

    Please tell me how to integrate it on my site (link given in website URL section).

    P.S. I have made customizations for including gravatar in post meta section and that’s why I don’t want to hurt its design.

    #825715
    Ender
    #825786
    Tom
    Lead Developer
    Lead Developer

    That second link that Ender provided should help.

    However, it’s ultimately up to Google whether they show the updated date or not – all we can do is display the necessary HTML/microdata.

    #825799
    Swadhin

    Hi Tom & Ender, thank you for those snippets.

    I think I have added that code.

    Can you please show me a way to integrate that plugin to show correctly in the post meta data.

    Thanks

    #826026
    Tom
    Lead Developer
    Lead Developer

    As far as I can see, that plugin couldn’t be necessary with that code snippet ๐Ÿ™‚

    #826181
    Swadhin

    Hi Tom,

    I used that code and it now shows two lat updated dates. I have included site and URL in the site section.

    Let me know if you need login details too.

    #826659
    Tom
    Lead Developer
    Lead Developer

    Do you have another filter added that alters the post meta? If so, can you share it with me?

    #826692
    epickenyan

    I also got two dates and I have tried the function twice (about two weeks ago and today). I only have the CSS for generatepress added to show last updated date and when I added the function, it showed double last updated dates. Removing the css removed both dates. http://prntscr.com/msbrga

    #826989
    Swadhin

    Yes Tom,

    I have this code for showing author gravatar, date and comment link in post 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;
    }

    Also, I do have this code to customize the author gravatar

    add_filter( 'generate_post_author_output', 'tu_add_author_gravatar' );
    function tu_add_author_gravatar() {
    	printf( ' <span class="byline">%1$s</span>',
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s %5$s<a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
    			__( 'by','generatepress'),
    			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' ) )
    		)
    	);
    }

    Apart from that, I have the following CSS related to dates:

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

    Thank you.

    #827017
    Tom
    Lead Developer
    Lead Developer

    So this would be your full (and only) function:

    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>';
    	}
    
    	$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() )
    	);
    
    	return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    }
    #827030
    Swadhin

    Thanks Tom,

    I applied it and it worked wonders!

    Thanks so much again… I am really relieved.

    #827463
    Sumit

    I want to display gravatar image, name, no. of comments and last modified date below post title.

    Please share code and also tell me where to add those codes.

    Waiting for your feedback.

    #827475
    David
    Staff
    Customer Support

    Sumit – i have answered this on your Topic.

    #827518
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! ๐Ÿ™‚

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