I would like to have my image descriptions added to every image caption on my site. No matter where the caption is shown, I would like to have the description prepended, if there is one to this image.

Nothing easier than that, I thought, and filtered the wp_get_attachment_caption to make sure it happens. And it works for every image displayed anywhere. Post thumbnails, images in posts... Except for the images loaded in a jetpack slider. The modified caption, although Jetpack itself calls wp_get_attachment_caption (here) simply does not show up.

Here is my function to modify the image caption:

function modify_image_caption( string $caption, int $image_id ) {

  $image = get_post( $image_id );
  $description = $image->post_content;

  if( ! $description )
    return $caption;

  return $description . ': ' . $caption;
add_filter( 'wp_get_attachment_caption', 'modify_image_caption', 10, 2);

What did I do wrong? Why does Jetpack only return the caption in a slider image?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.