0

I am trying to add a translatable string, like "posted on:" to my Wordpress theme post dates. I have already added a font-awesome icon next to it and I'd like to have the string after the icon. The code for the date is

$time = '<i class="fa fa-clock-o" aria-hidden="true"></i>' . '<time datetime=' . get_the_time('Y-m-d') . '>' . get_the_time('j F Y') . '</time>'

I know that, to make a string translatable in Wordpress, I need to add the string inside __(), but can I do so for the above code?

Any ideas?

1

You should use placeholders:

$time = sprintf( 
    '<i class="fa fa-clock-o" aria-hidden="true"></i> %s: 
     <time datetime="%s">%s</time>', 
     esc_html__('Posted on', 'textdomain'), 
     get_the_time('Y-m-d'), 
     get_the_time('j F Y') 
);
| improve this answer | |

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.