If you're looking for an easy way to display a “this article was published 6 minutes ago” on your WordPress website built with Oxygen Builder, this article is for you.
This guide is specifically created for the Oxygen Builder repeater element, but it can definitely be expanded to easy posts, and even a non-Oxygen WordPress website.
First, insert your date into the repeater element by using the dynamic data aspect of the builder. Don't add any additional things to this date, keep it in its default format.
The only additional step that you need to take is inserting a code block, and pasting in this PHP.
The changes will not display in the builder, but on the front end of your Oxygen Builder website, the post date will show as “published 28 minutes ago”, or something like that.
Keep in mind; you can display “published x time ago” by using this method on any WordPress website, not specifically Oxygen. To do that, you would probably need to install a plugin called code snippets, and paste that PHP in there. Then, you may need to edit your theme files, make a child theme, or do some other back end alterations.
<?php
function iso_post_time_ago () {
return sprintf( esc_html__( '%s ago', 'textdomain' ), human_time_diff(get_the_time ( 'U' ), current_time( 'timestamp' ) ) );
}
add_filter( 'get_the_date', 'iso_post_time_ago' );?>
Code language: HTML, XML (xml)
I can't seem to make this work
the code was breaking my page with the repeater element. So I used this inside a code block and it worked flawlessly:
<?php
echo sprintf( esc_html__( '%s' ago, 'textdomain' ), human_time_diff(get_the_time ( 'U' ), current_time( 'timestamp' )));
?>
minor correction with yours. the ' should come after ago not after %s so something like this
echo sprintf( esc_html__( '%s ago', 'textdomain' ), human_time_diff(get_the_time ( 'U' ), current_time( 'timestamp' )));
?>