Site logo

Archived topic

Unable to show last updated date on PAGES

20 replies · Started by Vijaykumar on January 21, 2023

Viewing posts 1–15 of 21

Hi
The CSS method to show last updated date here https://docs.generatepress.com/article/show-the-updated-post-date/ is working to show last updated date for wordpress POSTS only but I am finding it hard to show the last updated date for the wordpress PAGES.

Is there any different code for PAGES to show last updated date? Any tweak required for this css code? Or any other method?
I tried the filter mentioned here as well https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date but it's also not working for showing PAGE updated date.

Thanks so much, this worked!

Glad to hear that

I use a different method using a custom shortcode you might find useful so i’ll share

function post_modified_date() {
    return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );

usage:

Last Updated: [modified_date] to the page you desire. (I use it in a shortcode block in The gutenberg.

Thanks Scott!

Hi David
I see the last updated date is shown on frontend with this change but the published date is still in the backend when we inspect the page. We want to REMOVE the published date for both posts and pages including comments. Any idea how we can remove it entirely from the page? We don't want to show "datePublished" even in the code backend may it be added by theme or any plugin. Can this be done?

This filter is added. Can you please check.
Posts/pages still showing entries such as:

class="entry-date published" datetime='...
<meta property="article:published_time" content="..
"datePublished":"..

FYI,
We had the code below but when we updated to PHP 8 it started giving error like undefined '$time_string' error on server.

if ( ! function_exists( 'generate_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function generate_posted_on() 
{	
	$date = apply_filters( 'generate_post_date', true );
	$author = apply_filters( 'generate_post_author', true );
	//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() )
	);
	
	// If our date is enabled, show it
	if ( $date ) :
		printf( '<span style="float: left; margin-right: 3px;">Last Updated:</span><span class="posted-on">%1$s</span>',
			sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
				esc_url( get_permalink() ),
				esc_attr( get_the_time() ),
				$time_string
			)
		);
	endif;
	
	// If our author is enabled, show it
	if ( $author ) :
		printf( ' <span class="byline">%1$s</span>',
			sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$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() )
			)
		);
	endif;
	
}
endif;

Hi David
I mean page Html when we inspect live pages and posts. I have given example urls in my first message to test links.

We do not want to show the published date in any format on the page. I have given examples of 3 instances where it is currently being shown.

This archived topic is closed to new replies.