I am working on a multi language website. Some posts have external resources for download. 'Download' string which is wrapped in a tag for download is in english across all languages. How can I wrap these strings to make them translatable?

I tried search 'Download' and replace with <?php _e('Download', 'rkm') ?> but php block is wrapped in comment tags as it is, I presume, within the <?php the_content() ?> function.

If you need more info please do not hesitate to ask.

Thanks in advance!

  • The word "download" is part of the post content? Or it is in the template files? – gmazzap Aug 5 '14 at 10:22
  • @G.M. It is part of the post content – Bojana Šekeljić Aug 5 '14 at 10:26

Being part of the post content, the string can't be translated using translation function. You probably need a multilanguage plugin like WPML or Multilingual Press.

In that way you'll be able to have different "version" (one per language supported) of the same post.

However, if the only thing you need to translate is the word "Download" you can mind to create a shortcode and use it in the postcontent.


function my_download_btn_cb( $atts, $content = "" ) {
  $format = '<a href="%s"%s>%s</a>';
  $blank = isset( $atts['blank'] ) && $atts['blank'] ? ' target="_blank"' : '';
  $content = filter_var( $content, FILTER_SANITIZE_URL );
  return sprintf( $format, $content, $blank, __( 'Download', 'rkm' ) );

add_shortcode( 'download', 'my_download_btn_cb' );

Once you have this code in a plugin or in your functions.php, in your posts content you can use it like so:


or if you want to open the download link in a new window:

[download blank="1"]http://example.com/url/to/the/external/download[/download]

In this way the word 'Download' will be shown translated in the link according to current language (if there is a translation for it in the related .mo file, of course)

| improve this answer | |
  • Thanks a lot, I ll try using this approach. I am already using the wpml plugin, but administrators of the website used 'Download' in all languages, for some reason, and now it is up to me to fix it. – Bojana Šekeljić Aug 5 '14 at 10:54

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.