I am seeking help in appending text to image captions in WordPress. I have tried two different pieces of code without success. The image caption displays normally without the appended text.
I have tried the following:
add_filter('img_caption_shortcode', 'modify_caption_text', 10, 3);
function modify_caption_text($output, $attr, $content) {
$caption = isset($attr['caption']) ? $attr['caption'] : '';
$new_caption = $caption . ' - Custom Text';
return str_replace($caption, $new_caption, $output);
}
and
function append_image_credit_to_caption($output, $attr, $content) {
// Your additional text
$additional_text = "<em>Custom Text</em>";
// Append the additional text to the caption
$output .= $additional_text;
return $output;
}
add_filter('img_caption_shortcode', 'append_image_credit_to_caption', 10, 3);
As the code above is not returning any errors within WordPress, is there something I am overlooking?
Thank you