2

I need some help on how to correctly format this code snippet for translation:

<?php next_post_link( '%link', __( '<span class="meta-nav">←</span> Nästa nyhet') ); ?>

I've used this method in my theme before:

_e( 'Nästa nyhet', 'mytheme');

But I don't know how to correctly type the _e translation method in my link output. I want to translate "Nästa nyhet".

Anyone?

5
  • 2
    Remember, _e() will echo a translated string and __() will return a translated string.
    – EAMann
    Commented Oct 10, 2012 at 17:04
  • Hmm, I'm sorry I don't get it. I'm a designer guy just dabbling with wordpress themes and some minimal PHP. What's the difference in regard to translating wordpress strings? I've been using _e() throughout my theme and it has worked great so far. When should I use what?
    – Johan Dahl
    Commented Oct 10, 2012 at 17:28
  • Use _e() when you want to echo the content to the screen. Use __() when you want to return the translated string within a function for later manipulation.
    – EAMann
    Commented Oct 10, 2012 at 17:50
  • Sooo...If I wanted to translate the url slug of some taxonomy in my functions file, I would do that using __()? And for just a headline outputted on my page, _e() is correct?
    – Johan Dahl
    Commented Oct 10, 2012 at 17:59
  • 1
    Yes. Take a look at the Codex article for internationalization for more details ...
    – EAMann
    Commented Oct 10, 2012 at 18:24

1 Answer 1

2

Don't wrap the entire section in __(), just wrap the part you need to translate:

<?php next_post_link( '%link', '<span class="meta-nav">←</span> ' . __( 'Nästa nyhet', 'mytheme' ) ); ?>
1
  • Thank you! That worked! I'll keep your advice in mind :)
    – Johan Dahl
    Commented Oct 10, 2012 at 17:29

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.