Add Fancybox class to WordPress images

Here is another useful snippet for all you WordPress users.

If you use Fancybox with WordPress this snippet will automatically add the class “various” to images added in the WordPress editor.

You could also change the class name “various” to anything you want and use for other things:

function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
    $classes = 'various';
    if ( preg_match('/<a.*? class=".*?">/', $html) ) { $html = preg_replace('/(<a.*? class=".*?)(".*?>)/', '$1 ' . $classes . '$2', $html); }
    else { $html = preg_replace('/(<a.*?)>/', '$1 class="' . $classes . '" >', $html); }
    return $html;
}
add_filter('image_send_to_editor','give_linked_images_class',10,8);

Share this


 Back to Latest News

Build a FREE Website with Wix

Create a free website with Wix.com. Customise with Wix free website builder, no coding skills needed.


Recommended Hosting


Donations

All these templates are created as donationware, if you are going to use them in a commercial project or would like to contribute, please donate:

£ GBP


Looking for information about link removal? - Click Here

Number of Templates
26

Total Downloads
49925

Daily Downloads (Avg)
42

Download Website Templates © 2017 - HTML Sitemap

Website Design by Derby Web Design