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

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


Recommended Hosting

Number of Templates
26

Total Downloads
62890

Daily Downloads (Avg)
39

Download Website Templates © 2018 - HTML Sitemap - Privacy Policy

Website Design by Derby Web Design