Site logo

[Support request] Adding Update to an edited article

Home Forums Support [Support request] Adding Update to an edited article

Home Forums Support Adding Update to an edited article

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2430098
    Techibytes Media

    I want to have “recently updated on ….” on my article which I recently updated. I have this code `.posted-on .updated:before {
    content: “Last Updated “;
    }` on my generatepress childtheme but it seems not to be doing the work

    #2430111
    Ying
    Staff
    Customer Support

    Hi there,

    Can you link us to an article that recently updated?

    #2430130
    Techibytes Media
    #2430177
    Fernando
    Customer Support

    Hi Techibytes Media,

    To do so, try adding this PHP Snippet:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    	
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>';
    
    if ( get_the_date() !== get_the_modified_date() ) {
    	$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated: %4$s</time>
    	<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published: %2$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> ',
    $time_string
    );
    }, 10, 2 );

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

    #2430429
    Techibytes Media

    I am using the child theme, should this be on the function.php or in the style.css?

    #2430432
    Fernando
    Customer Support

    This code is PHP so you can add it either in functions.php or through a plugin called Code Snippets as mentioned in the article I shared.

    #2430442
    Techibytes Media

    Thank you, it works now

    #2430475
    Fernando
    Customer Support

    You’re welcome!

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