website templates, download web templates for free

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 using Krystal Hosting

Use the code DWTCODE at checkout to help us and also receive £5 credit back

Get Hosting - Use code DWTCODE


Share This Page

Help us increase our exposure by sharing us across social media:

Facebook

Twitter

Number of Templates
26

Total Downloads
97380

Daily Downloads (Avg)
27