0

I need to add a string in front of the following php code, what Is the best method of doing this?

<?php echo human_time_diff( get_the_time('U') ) . __(' ago', 'yourlanguageslug'); ?><br/>

2 Answers 2

1

<?php echo "Posted: ".human_time_diff( get_the_time('U') ) . __(' ago', 'yourlanguageslug'); ?><br/>

It's not that hard. but, you should these small things.

2
  • Thanks, It's literally the second time I've done anything with php. Jan 23, 2018 at 14:49
  • Glad to be of help. Jan 24, 2018 at 8:02
1

If you want to be able to translate the whole string, use printf().

Also, I'd escape the translations.

<?php printf( 
  esc_html__( 'Posted: %1$s ago', 'text-domain' ),
  human_time_diff( get_the_time( 'U' ) )
); ?>

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