Lee Willis

How to change text in a WordPress plugin

| 21 Comments

One of the great things about using an out-of-the-box solution like WordPress is that you can get something up and running pretty quickly. That’s been one of WordPress’ strengths over the years. However, if you’re building sites for other people then sometimes parts of the generic-ness seep through and detract from the overall feel of the solution. Specifically – terminology that is great in a generic solution isn’t always helpful in a custom, or specific solution.

None of this is a criticism of WordPress, but as you start building larger, or more complex sites you’ll probably want to start smoothing off some of these rough edges, and make sure the language of the site (frontend or admin side) makes sense in the specific context of the site you’re working on.

That’s something I come across frequently in my day job as a Drupal developer. Fortunately Drupal has the excellent String Overrides module. This lets you specify the current string, and a replacement, and will change the text whenever that string is used, with the caveat that the original string has to be passed through Drupal’s translation function t().

When someone recently asked me how to change some text in one of my own WordPress plugins – my first suggestion was this exact same approach. After all, all of my Premium plugins use translatable strings, and suggesting to someone that they should create a translation file just to change one or two strings for their needs has always seemed a bit excessive. So – I had a hunt around the WordPress.org repo for something similar, but couldn’t really find anything that did the job.

Figuring it’d be something fairly simple to achieve I set out to knock up a plugin that did the job. So next time you need to quickly change a string in WordPress, or a plugin you’re using – don’t hack it in the plugin – or in WordPress core, leaving your client unable to upgrade, give “Say What?” a go:

The strings we want to change

The strings we want to change

The say what page - setting up our string replacements

The say what page – setting up our string replacements

The text - automatically replaced for us

The text – automatically replaced for us

 

Say what?
by Ademti Software

An easy-to-use plugin that allows you to change translatable strings from plugins / themes and WordPress core without editing code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!

The plugin’s available for forking and contribution over on GitHub

Check out Say What Pro for:

  • String Discovery and autocomplete – find the strings you need without diving through code. Works with server-side and Javascript-rendered strings
  • Improved performance using text-domain-specific filters
  • Wildcard string replacements – replace individual words, or fragments across your whole site
  • Multi-lingual support – set different replacements for different languages on multi-lingual sites
  • Import/export features – Easy import/export of replacements through the user interface

Support this free plugin

As a business, we already donate a percentage of our profits from premium plugins to global climate change projects. You’re free to use this plugin free of charge, but if you do, please consider buying the world some trees in return. You’ll be creating employment for local families and restoring wildlife habitats.

Stats:

  • Current version: 2.2.5
  • Rating: 86(90 ratings)
  • Downloaded 618,845 times

21 Comments

  1. This plugin is just what I needed. Thanks! I think a lot of people could probably benefit from it, but perhaps it doesn’t rank in searches because of the creative name?

    • Hi Ken,

      Glad you’re finding it useful – you’re probably right about the name – I’ll see if I can’t add something into that.

  2. Hello,
    Great plugin !
    I’m testing the plugin, and I would like to know if we can translate the new strings ?
    After adding some strings, they do appear on front at the right places, but I can’t see them in my WPML string translation panel. (and thinking about it, it seems quite normal, since we don’t have the __() call in a specicic template) …
    Would you know how to replace a specific string AND its translation ?
    Thank you !

    • Hi,

      I’m a bit confused by your comments. The plugin will only work with translatable strings, it won’t work if your strings aren’t wrapped in __(), _e() or one of the other translation functions. Can you give me some more details on precisely what you’re trying to achieve?

      • Thank you for your answer.
        Let’s say I have a translatable string in a template :
        __(“my friends”)
        I can translate this string in french with .mo files and I do it :
        mes contacts

        Now, I would like to replace “friend” with “my contacts” in english too.
        But when I use your plugin, I end up with “my contacts” in english AND in french.

        Is this normal ?
        Thank you again !

        • Hi,

          If you’re comfortable preparing .mo files then I’d suggest just doing that for en_us. That said I’m not sure why you’d get a translated string AND a replaced one – you should get one or the other.

          • Yep, I’ll try the .mo file, that was my next move planned, thanks for the hint 🙂

            About the need, I don’t know, it seems obvious to me that I should be able to actually translate the string that I just changed, otherwise I see no reason to use a translating system.

          • I guess I’m a bit confused about why you’d want to change the string twice? You’re either “translating” it – in which case you can translate it how you like, or you want to change the original. I’m a bit confused about why you’d want to “change” the original, and then “translate” the changed string?

  3. Hi Lee,
    I am very hopeful that your Say What? plugin will solve my third-party-plugin-text-change woes. As an example, I am trying to change the string “Input your name here” in the following plugin function.php code:

    array(esc_html(Class_Project::getInstance()->conf(“seo_step_1”)), __(“Input your name here”, “classboard”)),

    I wrote the string “Input your name here” in the “Original string” field in your Say What? plugin (i.e. on the text changes page). I then entered “Please type your name here” (i.e. the new text that I wish to use) in the “Replacement string” field. I left the domain field blank because I wasn’t entirely sure what to input. After clicking the “Add” button, I didn’t notice any corresponding changes on my test website. I suspect that I am not using your cool plugin correctly. Can you provide me with some guidance on the proper inputs for the “Original string” and “Replacement string” fields?

    Many thanks,
    Sean

    • Hi,

      In the example you quoted, you need to set the domain to ‘classboard’ (without the quotes) for it to be picked up.

  4. It worked! Absolutely amazing! Your plugin has saved me countless hours of editing.

    Many thanks,
    Sean

  5. Absolutely! I just finished posting the review on WordPress.org. Thanks again for your help.

  6. Lee,
    First of all great work. I do Drupal development as well and I’ve used the String Overrides module a bunch of times. So I was excited to find somebody implementing a similar plugin with WordPress.

    That said, it appears that your plugin doesn’t support multi-byte character sets.
    If I enter Original String – “Post Comment”, Replacement String – “??????” (Japanese), I get a string of question marks as the new string after saving.

    Is this simple to fix?
    Thanks.

  7. btw
    I can use Japanese text elsewhere on the site without any problem.

    • Hi Paul,

      The honest answer is that I have no idea! The plugin doesn’t do anything specific that should stop it working – but maybe there’s something extra I need to do to enable them?

      If someone has any pointers happy to take a look.

  8. Usually with this kind of problem (aka mojibake) it’s because the code (or maybe database schema) hasn’t been set up as UTF-8.

    • The code doesn’t do anything to force a specific encoding. Does the data that gets saved to the database look correct? Does changing the collation of the database help?

  9. I’ve tried a bunch of different ways to replace tax with fees and no luck (a range of different domains, strings and replacements.) Any ideas would be appreciated

  10. Thank you very much!!

    This is What I need for my WordPress ?

    Greetings from Barcelona

Leave a Reply

Required fields are marked *.