0

I'm using the "Featured Image" meta box which allows you to attach a secondary thumbail to a post. The title for this box is defined in the Wordpress codebase like so:

__('Featured Image')

Which looks to be a wrapper for the translate methods. I'm wondering how to change this text without having to do any translation files. Is it as simple as an action or filter hook?

1 Answer 1

2

Sure, the gettext filter does exactly what you require.

Here's some code that should work out of the box:

function wpse31449_translate_my_stuff($translation, $text, $domain) {
    if ($text == 'Featured Image')
        return 'Post Image';
    return $translation;
}
add_filter( 'gettext', 'wpse31449_translate_my_stuff', null, 3 );

Note: if the translation is retrieved with a gettext context (_x() and _ex()) then the gettext_with_context filter has to be hooked to, which passes 4 arguments - the translation, the original string, the context and the domain to your filter.

Let me know if the answer is clear and/or how I can further improve it.

5
  • Incredibly clear, and exactly what I was looking for. Thanks! Commented Oct 19, 2011 at 5:41
  • Here's what I ended up doing, btw. typeoneerror.com/articles/post/… Commented Oct 19, 2011 at 6:39
  • 1
    Great post, well done! I like how you found an application for it. Make sure you mention our community that helped you figure this and any other questions that you may have had or will have, though wink wink
    – soulseekah
    Commented Oct 19, 2011 at 6:48
  • 1
    Oh, good call. Linked ya up. :) Commented Oct 19, 2011 at 15:10
  • I meant the WPStackExchange community in general, but big thanks, Benjamin, great blog, btw.
    – soulseekah
    Commented Oct 20, 2011 at 6:13

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.