• I’d like to add links into the photo captions for when I’m linking to a flickr user and using the caption as a photo credit.

    The caption is the alt tag and so when I insert html code into the caption box, it breaks the whole thing.

    Is there a workaround for adding a hyperlink to the photo caption text?

Viewing 7 replies - 16 through 22 (of 22 total)
  • Thank you peterebutler! It works fine!
    For the “shadowbox” option I did as you suggest:

    this.innerHTML = this.innerHTML.replace(new RegExp("{link:([^}]*)}([^{]*){/link}"), "<a href=\"$1\" rel=\"shadowbox\">$2</a>")

    I’ve taken Hainesy82’s great approach and tweaked it a bit.

    <script type="text/javascript">
    (function($){
    	$(function() {
    		$("p.wp-caption-text").each(function() {
    			var $caption = $(this).text();
    			$(this).html($caption);
    		});
    	});
    });
    </script>

    This method will allow you to add HTML to a caption inside of WordPress and have it parse out on your page.

    With the code above Hainesy82’s link would be reformatted like this:
    This is the caption text <a href="https://www.google.co.uk/">that links to google</a> - great!

    Hi, could reach to make that thing work.
    But I was wondering why this wasn’t a default feature of WordPress?
    Cheers

    I’ve tried adding each one of the jquery scripts (separately) into footer.php, and then editing in visual (using the built in WP box), and editing the html. No matter what I do, it still strips out the link. I’m in version 2.8.2, can someone ‘splain where I’m going wrong?

    Mike

    Hainesy82’s code works perfectly but for some reason it breaks the float: left styling. I’ve tried using the image uploader alignleft function, I’ve tried inserting css into the img tag – nothing works. It just won’t float.

    Is there something about the caption or the jquery code that breaks the float function and if so, is there a way to fix it?

    Update – it’s definitely the Caption shortcode, not the jquery that’s breaking the styling.

    Is there a way to use float and Caption together?

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Adding links to image captions’ is closed to new replies.