Move the captions of the image inside the link (tag) if added

I'm just looking for a relatively simple way to change the default output when a standard post image with a caption is linked somewhere (usually to another page), so the caption is included in the link. It is currently outside the link tag so as not to create a link as does the image.

I will eventually move the caption so that it covers the image. It is simply embarrassing that the image is properly linked to a separate page, but the caption (which will be the title of the page to which the link points) will not be.

The default output is currently:

History and mission

  • No matter what way to drag this text p.wp into the tag & # 39; a & # 39; a & # 39; a & # 39; a & # 39; with the image ???

If no link is added to a photo, it should simply behave normally. I've also considered using a gallery, but I did not see how to make each image a unique link to other pages.

NOTE: At the moment, I use the classic editor (with TinyMCE Advanced). I do not know if I'm going to Gutenberg right now, because it would open up a ton of possibilities for the client that I should consider and stylize appropriately. Because, you know, the customers …