Changing Plugin-generated Texts in the Frontend

How to change the text that Image Source Control outputs in the frontend.

Some of the text Image Source Control incorporates into the frontend is static. This includes the headings of the Global Source List, like “Title” or ”Attached to”.

Sometimes users ask me how they can change these labels. Therefore, I have listed my preferred method here.

Ideally, Image Source Control would have options for customizing all labels, as you can already do for the Overlay. However, this would make the plugin backend cluttered for most users. Since the plugin uses WordPress standards to translate text (= “gettext”), you can also adjust these with the help of a plugin like Loco Translate or the following code.

Let’s say you want to change the heading “Attachment ID” to “ID” and “Attached to” to “Post.” You can do this with the following PHP code:

add_filter( 'gettext', function( $translated_text, $untranslated_text, $domain ) {
    if ( 'image-source-control-isc' !== $domain ) {
        return $translated_text;
    }

    if ( 'Attachment ID' === $untranslated_text ) {
        $translated_text = 'ID';
    } elseif ( 'Attached to' === $untranslated_text ) {
        $translated_text = 'Post';
    }

    return $translated_text;
}, 20, 3 );Code language: PHP (php)

Note that the text to be changed should be specified as it appears in the source code. If you don’t use the English version, you can temporarily change your installation language to English to see these in the frontend, or look at the source code or translation files. The aforementioned Loco Translate can also help you with this.

You can insert the code listed above into the functions.php of a child theme, a custom plugin, or with the help of a plugin like Code Snippets on your site. I use the latter myself to keep track of backend adjustments.

PS: Did you know that with Image Source Control, you can hide and show individual columns of the Global Source List?

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?