0

How to amend (override) the time format of the comments (of the posts and pages), not touching the wordpress initial installation? I use a child theme and if it is possible in any way to do it from the child theme to prevent my changes been overwritten by the next WP update. I would prefer to use add_filter()

I am trying to use:

// define the get_comment_time callback 
function filter_get_comment_time( $date, $d, $gmt, $translate, $comment ) { 
    $d = "g:i:s";
    return $d; 
}; 

// add the filter 
add_filter( 'get_comment_time', 'filter_get_comment_time', 10, 5); 

But it returns only the string "g:i:s".

WP 4.9.4

1 Answer 1

2

You have to return the formatted date string, the following will work:

// define the get_comment_time callback 
function filter_get_comment_time( $date, $d, $gmt, $translate, $comment ) { 
  $d = "g:i:s";
  $date = mysql2date($d, $date, $translate);
  return $date;
}; 

// add the filter 
add_filter( 'get_comment_time', 'filter_get_comment_time', 10, 5);
4
  • Dear @Pabamato, thank you for your kind answer! It has solved the issue! Many thanks!
    – Arsenii
    Apr 4, 2018 at 14:15
  • The only thing I cannot get is that why WP does not check the GLOBAL date and time format, set in the General settings? I have set them to g:i:s and everywhere it works ecross the site, but only the comments...
    – Arsenii
    Apr 4, 2018 at 14:25
  • 1
    Hi @Arsenii, thanks for your warm feedback. I don't see a reason for not getting the global time format setting, do you have a custom comments template in your theme? As always if you want to go to the main source for the issue you can try deactivating all the plugins and/or switching to a diff theme, just to make sure there is nothing else filtering the time string result.
    – Pabamato
    Apr 4, 2018 at 15:07
  • Dear @Pabamato, thank you for your kind answer! yes, I found yesterday, that it came out to be because of a custom template in the theme.. I did need to make a custom copy of that template in the child-theme and everything got better! Thank you!
    – Arsenii
    Apr 5, 2018 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.