Hooked into wp_get_attachment_caption to add content to the default description; not working for jetpack slideshow. Why?

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?

Topic plugin-jetpack filters gallery Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.