• Hello guys,

    So, below is the WordPress default generated code for a gallery item:

    <div id='gallery-1' class='gallery galleryid-203 gallery-columns-3 gallery-size-thumbnail'>
    	<dl class='gallery-item'>
    		<dt class='gallery-icon landscape'>
    				<a href='image url'><img width="150" height="120" src="thumbnail image" class="attachment-thumbnail"/></a>
    		</dt>
    		<dd class='wp-caption-text gallery-caption'>Caption Text</dd>
    	</dl>
    </div>

    What I need, is to surround the caption text with the image url, so when the user clicks on the caption it will open the big image, like this:

    <dd class='wp-caption-text gallery-caption'><a href="image url">Caption Text</a></dd>

    I know I can do this via image gallery with a href in the caption text, but the site is for a client and I want to be done dynamically.

    I also found that this can be done in media.php (via functions.php), but I don’t know how…

    I hope I’ve made myself clear ??

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The gallery code is in media.php, but it has no filters to leverage in the normal sense. You hook the filter ‘post_gallery’ but when your filter callback returns something, the return is immediately output, bypassing the default gallery code entirely.

    So you have to basically copy the entire gallery_shortcode() function, altering as needed, then rename it and pass it as the filter callback function. It would be a good idea to check for any changes to the default function after each update and incorporate them into your version where applicable.

Viewing 1 replies (of 1 total)
  • The topic ‘How to dynamically insert a href for the image caption?’ is closed to new replies.