Archived topic
Customise
7 replies · Started by An Nguyen on November 4, 2019
Hi Team,
I want to customise meta data after title in blog page following this style : "by {image-avatar} {author-name}, {date publish}, {how long post's publish}"
{how long post's publish}: Ex: 1min, 1hour, 1month ago, 1year ago.
Thanks Team in advance.
Hi there,
So are we basically keeping the same layout you currently have, but replacing the "time to read" to "how long its been published"?
Hi Tom,
It's right! In {date publish}, can we remove {year}?
Thanks Tom.
Hi there,
removing the Year from the Post date is a WP thing and can be changed in Dashboard > Settings > General.
You can try this snippet from my own personal collection to generate the Posted since time:
function db_posted_since_time() {
ob_start();
global $post;
$date = $post->post_date;
$time = get_post_time('G', true, $post);
$mytime = time() - $time;
if($mytime > 0 && $mytime < 7*24*60*60)
$mytimestamp = sprintf(__('%s ago'), human_time_diff($time));
else
$mytimestamp = date(get_option('date_format'), strtotime($date));
echo $mytimestamp;
return ob_get_clean();
}
add_shortcode( 'posted-since','db_posted_since_time' );
It creates a [posted-since] shortocde
Can i ask that you review our support forum guidelines when you next raise a support topic. The majority of what you're requesting is custom development. And although we try to assist all users wherever we can we have limited resources to apply what should be paid development.
Hi David,
I’m sure that I tried on my best for searching resources however, I got wrong format of meta data from this forum. It also changes my current layout. Actually, I don’t want us take more time to debug unexpected errors rather than I ask a support topic and solving by your professional skills. Both of us can save time.
I always tried to use GP’s forum & guidelines first before asking a request. An example is that my current website is a result of combining different parts from guidelines and forum. Totally, it’s not 100% of getting them from my support topics.
I know you have limited resources. In case, if my request in the same with previous one you can show me link. I can try following this link. Sometimes, I missed them because GP’s resources is so big and GP’s version is updated by time. I’m not sure it’s relevant to my case or out of date.
Thanks for your kind support. I appreciate about it.
If my request is out of GP’s support, please let me know!
Update: Your code doesn't work. It shows the same published date.
Hi there,
How are you currently customizing your post meta area? Can you share the code?
Let me know :)
This is this code:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline_readtime_social_applaud');
function tu_fancy_byline_readtime_social_applaud( $date ) {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
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() ),
get_avatar( get_the_author_meta( 'ID' ) )
)
);
echo $date;
echo '<span class="posted-since"> ' . do_shortcode('[posted-since]') . '</span>';
echo '<span class="read-time"> ' . do_shortcode('[reading_time]') . '</span>'; // can add text after "read-time"> '
}
What if you just use this?: https://wordpress.org/plugins/meks-time-ago/
That way it will replace the current date with the time ago date.