Support » Fixing WordPress » wordpress 5 linked gallery images caption outside the a tag

  • pointnet

    (@pointnet)


    Hello, is there a reason because in the core image gallery the caption of each image is outside of the <a> tag?

    Now it is something like that:

    <figure>
      <a href="url-image.jpg">
        <img src="url-image.jpg" />
      </a>
    
      <figcaption>caption here</figcaption>
    </figure>

    The problem is that the caption is outside the a tag and in a lot of situation is going to make impossible to click on the link, for example in mobile devices.

    Wouldn’t it be better to put the caption inside the a tag?

    something like that:

    <figure>
      <a href="url-image.jpg">
        <img src="url-image.jpg" />
    
       <figcaption>caption here</figcaption>
    
      </a>
    </figure>

    In this way the caption is clickable and it is also easier to create css hover effects without preventing the possibility of clicking on the link.

    I`m new to wordpress, is there a template to override in order to achieve that?

    • This topic was modified 4 months ago by  pointnet.
    • This topic was modified 4 months ago by  pointnet.
    • This topic was modified 4 months ago by  pointnet.
    • This topic was modified 4 months ago by  bcworkz. Reason: html fixed
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Putting both image and caption in the same anchor tag can cause strange behavior with some themes. It’s better to link the image and text separately, even if they go to the same location. Even so, captions as links will not display correctly with some themes.

    A theme template cannot easily override the HTML generated by WP. You need a plugin to provide an alternative image block which links captions. I’m unaware of such a plugin, it may need to be custom developed.

    I case you didn’t notice, you can manually link captions to anywhere you like. I realize this extra step would be a royal pain when many images are involved.

    You could alternately write some content filter code that searches out linked images with captions and automatically linkifies the caption based on the prior image link. Such code is inherently fragile and inefficient, but it is possible.

    pointnet

    (@pointnet)

    Thanks for your reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.