[Resolved] Posted Date and Updated Date

Home Forums Support [Resolved] Posted Date and Updated Date

Home Forums Support Posted Date and Updated Date

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #777508
    Matt

    I know this question has been asked before, but I just can’t figure out the best way to do it. If someone could take a look at my site and tell me what to do I’d really appreciate it.

    I’d like to have the date appear as follows:

    Posted Date: XXXXXX Updated Date: XXXXXX

    I added my URL for the admins to see.

    Thanks for the help!

    #777709
    Leo
    Staff
    Customer Support

    Hi there,

    Add this PHP snippet:

    add_filter( 'generate_post_date_output', function( $output ) {
    	$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_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() )
    	);
    
    	echo sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
    			esc_url( get_permalink() ),
    			esc_attr( get_the_time() ),
    			$time_string
    		)
    	);
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    And this CSS snippet:

    .posted-on .updated {
        display: block;
    }
    .posted-on .updated + .entry-date {
        display: none;
    }
    .posted-on .updated:before {
        content: " Updated Date: ";
    }
    .posted-on .published:before {
        content: "Posted Date: ";
    }

    Adding CSS: https://docs.generatepress.com/article/adding-css/

    We are working on better methods to make this easier πŸ™‚

    #778340
    Matt

    Thanks, I add the PHP and CSS, but it doesn’t look right.

    Can you please take a look at one of my blog post pages – there are some spaces missing.

    Also, I would prefer to have the Last Updated date appear a line below the Posted date.

    I also would like everything to appear below the featured image I think πŸ™‚

    Thanks for the help.

    #778443
    Leo
    Staff
    Customer Support

    Updated the CSS above.

    #778459
    Matt
    #778460
    Leo
    Staff
    Customer Support

    I’m still seeing the old CSS being added.

    Have you tried clearing your caching plugin?

    #778511
    Matt

    Yes, even cleared Cloudflare.

    #778617
    Leo
    Staff
    Customer Support

    I’m still seeing the old CSS being added in the source:
    https://www.screencast.com/t/f9mQhpnT

    Looks like it’s added in Additional CSS in the customizer.

    #778654
    Matt

    Opps, forgot to delete what was there when I moved it over to the Simple CSS plugin πŸ™‚

    Almost done.

    I would prefer to not display the date on tag or category pages:

    https://www.yardcare.life/tag/buying-guide/

    I think it looks funny.

    #778761
    Leo
    Staff
    Customer Support

    You can either use this filter:
    https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98date%E2%80%99

    Or this CSS:

    .tag .posted-on, .tag .updated,
    .category .posted-on, .category .updated {
        display: none;
    }
    #779236
    Matt

    Got it, thank you!

    #779360
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

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