• Resolved Purusha

    (@gphoenix5727)


    Is there a way I can change the “Image courtesy of” test to “Cropped Image Copyright of”.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author pepe

    (@pputzer)

    You could filter the credit markup using media_credit_at_end or the “translation” using ngettext.

    Thread Starter Purusha

    (@gphoenix5727)

    Thank you that’s great. I haven’t used thar before, what a simple trick…

    Thread Starter Purusha

    (@gphoenix5727)

    I have tried various methods with no success, my current code is:

    add_filter('gettext', 'change_text', 20, 3);
    add_filter('ngettext', 'change_text', 20, 3);
    
    function change_text( $translation, $text, $domain ) {
        $custom_text = array(
            'Image courtesy of' => 'Image (cropped) copyright of',
        );
        if( array_key_exists( $translation, $custom_text ) ) {
            $translation = $custom_text[$translation];
        }
        return $translation;
    }

    Can you help?

    Thread Starter Purusha

    (@gphoenix5727)

    I have resolved it using Text Replace Plugin

    Plugin Author pepe

    (@pputzer)

    Hi @gphoenix5727, you are adding a filter with the gettext arguments to the ngettext filter which expects these parameters:

    • string $translation Translated text.
    • string $single The text to be used if the number is singular.
    • string $plural The text to be used if the number is plural.
    • string $number The number to compare against to use either the singular or plural form.
    • string $domain Text domain. Unique identifier for retrieving translated strings.

    Also, the translated strings contain positional parameters for inserting the actual image credits which need to be accounted for during the replacement.

    Since you are probably running WordPress >= 5.5, it would probably be best to hook to the domain variant (ngettext_media-credit). Something like this should work:

    
    add_filter('ngettext_media-credit', 'my_change_text', 20, 4);
    
    function my_change_text( $translation, $single, $plural, $number ) {
        if ( 'Image courtesy of %2$s%1$s' === $single && 'Images courtesy of %2$s and %1$s' === $plural ) {
            // Modify $translation based on $number - could be plural!
            ...
        }
    
        return $translation;
    }
    

    sorry for the maybe silly question … where to put this code?

    Plugin Author pepe

    (@pputzer)

    @cgra You could put this into your child theme’s functions.php, but please note that it is not a complete implementation, just the necessary scaffolding. Since you had to ask, I’m assuming you are not a PHP developer yourself. In that case it would be to hire one to do the necessary customizations for your website (probably if overkill if this is the only feature missing, but I guess there will be others).

    Hi pepe, you are assuming right ?? But I have many years experience with tweeks here and there and sometimes you have to modify in functions.php, sometimes in post.php, sometimes in the php of the plugin itself. I’ll give it a try in my functions.php, thanks for the quick answer!

    ok, I don’t get it to work. Could you help me with the full code to get the output “Images: ” and in german “Bilder: ” (single an plural) instead of “Image courtesy of”?
    That would be great ??

    Plugin Author pepe

    (@pputzer)

    Can you post the code you did try, @cgra?

    I tried this (sorry in advance if this is totally stupid …)

    add_filter('ngettext_media-credit', 'my_change_text', 20, 4);
    
    function my_change_text( $translation, $single, $plural, $number ) {
        if ( 'Image courtesy of %2$s%1$s' === $single && 'Images courtesy of %2$s and %1$s' === $plural ) {
            // Modify $translation based on $number - could be plural!
    	$custom_text = array(
            'Image courtesy of' => 'Image:',
        );
        if( array_key_exists( $translation, $custom_text ) ) {
            $translation = $custom_text[$translation];
        }
        return $translation;
    }
    }
    Plugin Author pepe

    (@pputzer)

    Yeah this can’t work. Try this snippet (not tested and really only valid if your target language is German and nothing else).

    add_filter('ngettext_media-credit', 'my_change_text', 20, 4);
    
    function my_change_text( $translation, $single, $plural, $number ) {
        if ( 'Image courtesy of %2$s%1$s' === $single && 'Images courtesy of %2$s and %1$s' === $plural ) {
            // Modify $translation based on $number - could be plural!
            $translation = $number > 1 ? 'Bilder: %2$s und %1$s' : 'Bild: %2$s%1$s';
        }
    
        return $translation;
    }

    Hi pepe, thank you so much, it works perfectly! As we are only targeting german language with our online-magazine this is the solution!
    You can take a look if you want here:
    https://vanlifemagazin.eu/the-american-way-of-drive-die-geschichte-der-kult-caravans-von-airstream/
    (magazine is in development)
    Kind regards,
    Christian

    Plugin Author pepe

    (@pputzer)

    There will be a new filter hook media_credit_at_end_use_short_label to enable the short form (Images:) in version 4.2.0.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Courtesy Text’ is closed to new replies.