Custom date/time format | WordPress.org
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.
مشاهده پاسخ های این مطلب
---------------------------------------------
این مطلب از سایت انجمن وردپرس گردآوری شده است و کلیه حقوق مطلق به انجمن وردپرس می باشد در صورت مغایرت و یا بروز مشکل اطلاع دهید تا حذف گردد
منبع: انجمن وردپرس