Saturday, December 20, 2014

Make WordPress image captions clickable with two lines of jQuery

I don't like the default behavior of image links with captions in WordPress. Clicking on the image redirects you to the target, but clicking on the caption does not. Here's a simple jQuery script that automatically handles all clicks on image captions:

$(document).on('click', '.wp-caption > a', function(e) { e.stopPropagation(); });
$(document).on('click', '.wp-caption', function(e) { $(this).find('a').click(); });
This needs to be added to the jQuery(document).ready(function($) {... } section of your theme.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home