Archived topic
How we can set post meta (Author name | Comment Count | Last Updated Date) ?
7 replies · Started by Akash on March 26, 2020
How we can set post meta (Author name | Comment Count | Last Updated Date). I also show reference image for more details. Please share code without plugin how we can setup in single post and archive post.
Image Link: https://prnt.sc/rn5ip7
Hi there,
Would this be for both blog listing page and single post?
Yes, blog listing page and single post
Hi there,
Add this PHP snippet:
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'comments-link',
'date',
);
} );
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
if ( '' === $item ) {
return '';
}
if ( 'comments-link' === $item ) {
return ' | ';
}
if ( 'date' === $item ) {
return ' | ';
}
return $output;
}, 50, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/
And this CSS to start:
.single .comments-link {
display: inline-block;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
Thanks for help LEO,
I have some question:
1) How we can remove by before author name
2) How we can add vertical bar after comment (see attached image for more details)
Image 1: https://prnt.sc/ro8p6j
3) How we can remove comment count below excerpt in blog listing page (see attached image for more details)
Image 2: https://prnt.sc/ro8pyk
1) Edit the PHP above:
https://generatepress.com/forums/topic/how-we-can-set-post-meta-author-name-comment-count-last-updated-date/#post-1212161
2) How are you adding the last updated date currently? Can you link me to the page in question?
3) You'd need this filter:
https://docs.generatepress.com/article/generate_footer_entry_meta_items/
Hi LEO
2) How are you adding the last updated date currently? Can you link me to the page in question?
I am using Last modified date using this code:
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$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="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated On %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() )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
how we can show vertical bar before last maodified date.
3) How we can remove meta in blog archive footer.
For more information see image: https://prnt.sc/rx8blm
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know :)