Hi @notsurewhatname
This depends on how you’re adding the date. The easiest way to achieve this is still through a Block Element.
See: https://share.getcloudapp.com/kpu427Ad/annotate
Or are you trying to manually modify the WP generated post meta? To confirm, may we know how you wish to add the post meta?
Hope to hear from you soon! 🙂
Hi,
Thanks for getting back to me!
As I mentioned I prefer not using a block element if that’s possible, I would prefer a PHP/CSS solution.
So yes I would prefer to modify the generated post meta
Thank you!
You can filter the Post Meta data the filter hooks available: https://github.com/tomusborne/generatepress/blob/adfe090929b0515cdf894f4c6b722cfe8c0790dc/inc/structure/post-meta.php#:~:text=*/-,function%20generate_do_post_meta_item(%20%24item%20)%20%7B,%7D,-add_filter(%20%27generate_inside_post_meta_item_output%27%2C%20%27generate_do_post_meta_prefix
You can also remove all Post Meta:
add_action( 'wp','tu_remove_blog_meta' );
function tu_remove_blog_meta() {
add_filter( 'generate_post_date_output','__return_false' );
add_filter( 'generate_post_author_output','__return_false' );
add_filter( 'generate_category_list_output','__return_false' );
add_filter( 'generate_tag_list_output','__return_false' );
add_filter( 'generate_show_comments','__return_false' );
}
And then add your specific code.
Something like:
<?php echo ‘<span> by’ . get_the_author() . ‘published on’ . get_the_date( 'D M j' ) . ‘</span>’; ?>
Then to get the author image, maybe this article can help: https://webappguides.com/get-author-image-in-wordpress-without-plugin/
Lastly, you’ll need to hook this to your preferred location and you can go back to the GP Github repository to chose a hook of your preference.
Hope this helps! 🙂
Hi Fernando,
Don’t you think your way is a bit complicated, to use hooks?
I was reading the generatepress forums and found this https://generatepress.com/forums/topic/add-author-image-to-single-post-entry-meta/ and it looks like there is a much easier PHP/CSS solution but I just can’t figure out what the right code is to
A. Display when posts are updated as well
B. Change the arrangement of the data to the example image I showed
If you know anything that can help with these it would be great!
ying
(@yingscarlett)
Hi there,
You can use the exact PHP and CSS from the solution you found.
Then add this CSS to re-position the author name and date:
.entry-meta .avatar {
width: 25px;
border-radius: 50%;
vertical-align: middle;
margin: 0 5px;
}
.entry-meta {
display: flex;
}
.entry-meta img {
order: 1;
}
.entry-meta span.byline {
order: 2;
margin-right: 20px;
}
.entry-meta span.posted-on {
order: 3;
}
.entry-meta span.posted-on:before {
content:'Published on ';
}
Hi, thanks so much that worked! Just 2 questions:
1. Do you know how I can make the author image link to the author profile page as well (like author name?)
2. Is it possible for the PHP to know if the article was “updated” to change the text from “published” to “updated” on the front end?
Thanks once again
ying
(@yingscarlett)
1. You can modify the PHP to something like this:
add_filter( 'generate_post_author_output', function( $output ) {
$avatar = get_avatar( get_the_author_meta( 'ID' ) );
$author_archive = get_author_posts_url (get_the_author_meta( 'ID' ));
if ( $avatar ) {
return '<a href='. esc_url( $author_archive ).'>'. $avatar .'</a>' . $output;
}
return $output;
} );
2. Published date and Updated date are both in the HTML, you just need some CSS. This article should be helpful:
https://docs.generatepress.com/article/show-the-updated-post-date/