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
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:
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:
Number of Templates
26
Total Downloads
99975
Daily Downloads (Avg)
26