Archived topic
Show last modified date to pages/posts
7 replies · Started by generatepressiscool on November 1, 2016
Plugin is amazing, great work. Please raise your prices, this is a joke.
Q: I already did this: https://generatepress.com/forums/topic/modified-date/
Modified date shows fine for posts now under title. I want to tweak this more:
1) Posts show "Last update: dd/mm/yy by Author" => how to add "Last update" part?
2) How to do the same for pages? Pages currently show nothing, would like it to show it there as well as we have big content saved as paged.
3) When we have #2 => how to exxclude certain pages to have last update/author? (ex: contact/signup page etc)
Hi there,
I just updated that function so it's using the latest code from the theme.
1. Find this line: <span class="posted-on">%1$s</span>
And replace it with this: <span class="posted-on">Last updated: %1$s</span>
2. You can do this with another function:
add_action( 'generate_after_entry_header', 'tu_page_post_meta' );
function tu_page_post_meta()
{
if ( 'page' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
3. Not too sure what you mean? You could hide it from specific pages by adding this CSS into the Simple CSS meta box:
.posted-on .updated {
display: none;
}
Simple CSS: https://wordpress.org/plugins/simple-css/
Hope this helps :)
HI Tom - thanks for the help.
1) This works, thank.
2) This doesn't work - nothing is showing for pages after adding this to generate-simple-php/custom.php Please advise
3) I believe #2 will have last updated show on every single post and page. Let's say we have pages like contact page where we do not want last update to show because it's not relevant there. How can we exclude the last update/author to show on that particular page? Meaning: we want last update/author to show on ALL pages by default, except on a handful of pages like contact page where it's not relevant.
2. Did you update the original function you found in that topic with the new version?
3. I understand, the method I mentioned above should do this :)
This is what I added
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 );
//$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() )
);
// If our date is enabled, show it
if ( $date ) :
printf( '<span class="posted-on">Last updated: %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;
/* Add Last update below titles, for pages */
if ( ! function_exists( 'generate_post_meta' ) ) :
/**
* Build the post meta
*
* @since 1.3.29
*/
add_action( 'generate_after_entry_title', 'generate_post_meta' );
function generate_post_meta()
{
if ( 'post' == get_post_type() || 'page' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
endif;
Ah, I just adjusted the function in #2 up here: https://generatepress.com/forums/topic/show-last-modified-date-to-pagesposts/#post-240919
Let me know :)
Okay that works - with the two together now.
For the CSS, this is what I needed
.entry-meta {
display: none;
}
thanks for help
You're welcome :)