最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Move Image Captions Inside Link (<a> tag) if Added

matteradmin6PV0评论

I'm just looking for a relatively simple way to modify the default output when a standard post image with a caption is linked somewhere (generally to another page), so that the caption is included in the link. It currently resides outside of the link tag so that it doesn't link like the image does.

I'll eventually be moving the caption up so it overlays the image. It's just awkward that the image will link properly to a separate page, but the caption (which will be the title of the page that the link points to) will not.

The default output is currently:

<div id="attachment_xxx" style="width: 480px" class="wp-caption alignnone">
<a href="/about/history-mission/">
<img class="size-medium wp-image-1679" src=".jpg" alt="" width="470" height="313" srcset="[multiple image sizes]" sizes="[proper sizes]">
</a>
<p id="caption-attachment-1679" class="wp-caption-text">History & Mission</p>
</div>
  • Any way to get that p.wp-caption-text to slide into the 'a' tag with the image???

If there is no link added to a photo, it should just behave normally. I also thought about using a gallery, but didn't see a way to make each image a unique link to other pages.

NOTE: For now I'm using the classic editor (w/ TinyMCE Advanced). Not sure if I'll switch to Gutenberg yet, as that would open a TON of possibilities up to the client that I would have to account for & style appropriately. Because, you know, clients...

THANKS!

Post a comment

comment list (0)

  1. No comments so far