cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra

Automatically Add rel=”lightbox” To All Embedded Images In A Post

Although using the Lightbox plugin can be a nice way of giving your readers a great experience in viewing your images in your blog, it can also become a bit tedious adding the rel=”lightbox” attribute to each image that you want to open with it. But thanks to Tyler Longren‘s code snippet, you won’t have to anymore.

Copy/paste the code below in to your functions.php file. Once done, every image you embed in a post will automatically have a rel=”lighbox” attribute added to it.

add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
 }

And by the way, in line 5 of the code you can change the rel=”lightbox” to whatever you prefer as Tyler noted that some viewer scripts use rel=”thumbnail” among other things. This snippet also adds the post title as the title attribute of the image’s anchor tag.

Related Posts

Themeum’s Flat Theme Multipurpose WordPress Theme

Weblizar Premium Responsive Theme

Automattic Buys WooCommerce Plugin for WordPress

Localbiz Business Theme for WordPress