Add fancybox to all images in WordPress

Glenn Glenn's Blog 0 Comments

Another quick WordPress snippet.

Assuming that you have fancybox linked up to your WordPress install you can add the following to your theme’s functions.php file to open all images that are linked to their full size image with jQuery Fancy Box:-



// Add Fancy Box to Images
add_action('wp_footer','auto_fancy_box');
function auto_fancy_box(){
 if (!is_single() && !is_page())
 return;
 ?>
 <SCRIPT TYPE="text/javascript">
 jQuery(document).ready(function(){
 jQuery(".div-containing-your-images").find("a:has(img)").addClass('group');
 jQuery("a.group").fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':false});
 });
 </SCRIPT>
<?php
}

About the Author
Add fancybox to all images in WordPress Add fancybox to all images in WordPress 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced WordPress Web Developer, Front-end and Back-end Developer & New Media Specialist with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries built up over a number of years.

Leave a Reply

Your email address will not be published. Required fields are marked *


*