The following function generates the plain output eg. No comments, 1 comment etc.

    __( 'No comments', 'textdomain' ), 
    __( '1 Comment', 'textdomain' ), 
    __( '% Comments', 'textdomain' ) 

However I want to wrap the first word/number in an html tag, to get following output:

<span>No</span> comments
<span>1</span> comment

How can I do that?

1 Answer 1


You can replace __( 'No comments', 'textdomain' ) with __( '<span>No</span> comments', 'textdomain' ), there is nothing that stops you to do it.

In general, HTML inside translatable strings are not recommended but if you really need the span tags, you have not other choice to add them server side. I strongly recommend to think why do you need those <span> and investigate if you can archive the same result without them.

More in i18n for WordPress Developers: HTML in translatable strings

Your Answer

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

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