Custom date/time format | WordPress.org

[ad_1]

Hello, I am looking for a way to change date/time template only on the front page for articles written less than 24 hours.

Below is my code snippet, but it replaces wordpress’s default date/time setting. Would like to know how to call wordpress’s default.

add_filter('get_the_date', 'meks_convert_to_time_ago', 10, 1); //override date display
add_filter('the_date', 'meks_convert_to_time_ago', 10, 1); //override date display
add_filter('get_the_time', 'meks_convert_to_time_ago', 10, 1); //override time display
add_filter('the_time', 'meks_convert_to_time_ago', 10, 1); //override time display

    /* Callback function for post time and date filter hooks */
    function meks_convert_to_time_ago($orig_time) {
		global $post;
		$orig_time = strtotime($post->post_date);
		if (is_front_page() &  (time() - $orig_time) < 60*60*24 ) {
            return human_time_diff($orig_time, current_time('timestamp')) . ' ' . __('전');
		} else {
		return date('Y-m-d', $orig_time);
		}
}

The last line for calling date(‘Y-m-d’, $orig_time) is an issue here. I removed the entire else conditions, then I have unix time (16xxxxxx) instead of real time. Instead of ‘Y-m-d’, as long as I can call wordpress’s default, I believe I can work this out.

Plz let me know if there is any solution or workaround. Thx.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer