Does anyone know how I can change this date format to time ago rather than DD/MM/YY

<?php the_time('M j, Y') ?>



There is a function for that: human_time_diff(). Use it like so: (U because we want the unix timestamp)

<?php echo human_time_diff( get_the_time('U') ); ?>

If you want additional text, you can use the following

<?php printf (esc_html__('%s ago', 'yourlanguageslug'), human_time_diff(get_the_time('U'))); ?>
  • Hi @kero, how do I add "ago" on to the end of this? – Jordan Kellett Jan 22 '18 at 15:54
  • @JordanKellett Please see my update – kero Jan 22 '18 at 15:56
  • Ah right, so I add both lines of code? – Jordan Kellett Jan 22 '18 at 16:13
  • @JordanKellett You can add either line, just using the bottom one is fine! – kero Jan 22 '18 at 16:28
  • Hmm, the bottom one only seems to display the "&s ago" when I add it into the php for some reason. – Jordan Kellett Jan 22 '18 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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