11

Today I work through a theme to get a better understanding of WordPress and templating. I discovered this:

<?php 
printf( 
    __('Designed by %s', 'Anyword'), 
    '<a href="http://www.example.com">Blub</a>'
); 
?>

I know it shows "Designed by Blub" (Where Blub is linked) But what does the __() mean or why is there a string insert? What for is the Anyword?

Can someone exactly explain this line for me?

8

It's used for translate text.

The second argument is a kind of namespace (called domain here) to retrieve the translation (for example from a dedicated file or something else).

So Anyword here, should be the guy behind the template, or the company or what ever that can be a domain/namespace.

edit:

The doc from wordpress give more explanation on how to internationalizing a plugin:


Add this to the Plugin code to make sure the language file(s) are loaded:

load_plugin_textdomain('your-unique-name', false, basename( dirname( __FILE__ ) ) . '/languages' );

To fetch a string simply use __('String name','your-unique-name'); to return the translation or _e('String name','your-unique-name'); to echo the translation. Translations will then go into your plugin's /languages folder.


For your plugin/theme, the your-unique-name seems to be Anyword.

  • There are some language files in the theme. How does the arguement know to use them for only the 'Anyword'? – Denny Mueller Jul 2 '12 at 15:17
  • I've updated my answer with a better part from the WP doc. – j0k Jul 2 '12 at 15:21

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.