Archived topic
Adding Update to an edited article
7 replies · Started by Techibytes Media on November 23, 2022
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
Hi there,
Can you link us to an article that recently updated?
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
I am using the child theme, should this be on the function.php or in the style.css?
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.
Thank you, it works now
You're welcome!