Pieter Goosen
Pieter Goosen

Reputation: 9941

Localizing a string with a tag inside

I have the following sting that I need to localize for translation

<?php echo 'Click <a href="'. esc_url( get_permalink() ) . '">here</a> to go and wacth the video.' ?>

My problem is the <a href="'. esc_url( get_permalink() ) . '">here</a> part in the middle of the sentence. I did try to break it up like this

<?php printf(__('Click %s to go and wacth the video.', 'pietergoosen'), '<a href="'. esc_url( get_permalink() ) . '">here</a>'); ?>

This works, but the word here inside the <a> tag then can't be translated.

Any suggestions how this can be solved

Upvotes: 0

Views: 37

Answers (1)

levi
levi

Reputation: 25071

You can split the tag into two separate strings:

printf(__('Click %shere%s to go and wacth the video.', 'pietergoosen'), '<a href="'. esc_url( get_permalink() ) . '">', '</a>');

Upvotes: 1

Related Questions