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/>

closed as off-topic by Dave Romsey, Jacob Peattie, kaiser Jan 24 '18 at 22:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

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.

  • Thanks, It's literally the second time I've done anything with php. – Jordan Kellett Jan 23 '18 at 14:49
  • Glad to be of help. – Dilip Gupta Jan 24 '18 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.