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;

Share this

 Back to Latest News

Recommended Tools

Create a free website with Customize with Wix's free website builder, no coding skills needed.

Recommended Hosting


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:


Looking for information about link removal? - Click Here

Number of Templates

Total Downloads

Daily Downloads (Avg)

Download Website Templates © 2018 - HTML Sitemap

Website Design by Derby Web Design