Support » Plugins and Hacks » Automatic adding Lightbox rel and group to images in posts?

  • Resolved Michiel

    (@michiel)


    I really like Lightbox but do not want to go through ### posts to update each and every image…. Is there a way to do this automatically?

    Thought to add the REL=Lightbox and GROUP tag automatically with the following plugin:

    <?php
    /*
    Plugin Name: Add lightbox
    */
    
    define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
    
    function addlightboxrel_replace($string) {
    	$pattern = '/(<a(.*?)href="([^"]*.)'.IMAGE_FILETYPE.'"(.*?)><img)/ie';
      	$replacement = '(strstr("25"," rel=") ? "1" : "<a rel="lightbox[imagegroup]"2href="34"5><img")';
    	return preg_replace($pattern, $replacement, $string);
    }
    
    add_filter('the_content', 'addlightboxrel_replace');
    
    ?>

    But it is not working…. any ideas?

    Many thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Michiel

    (@michiel)

    Any ideas anybody? Would think this must be useful for many others that do not want to go through xxx posts to update manually the image tags.

    alakhnor

    (@alakhnor)

    function addlightboxrel_replace($string)
    {
    	$pattern = '/<a(.*?)href="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
      	$replacement = '<a$1href="$2.$3" rel="Lightbox[imagegroup]$4>';
    	return preg_replace($pattern, $replacement, $string);
    }
    manumanu

    (@manumanu)

    sir, is this still in development?

    MANY THANKS! It works now!
    Below the full code.

    I still would lile to make the [imagegroup] unique per post, so that all images per post are grouped in one lightbox set.

    How could I implement that? I tried adding post_title but that did not work…

    <?php
    /*
    Plugin Name: Add lightbox
    */
    
    define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
    
    function addlightboxrel_replace($string) {
    	$pattern = '/<a(.*?)href="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
      	$replacement = '<a$1href="$2.$3" rel=\'Lightbox[imagegroup]\'$4>';
    	return preg_replace($pattern, $replacement, $string);
    }
    
    add_filter('the_content', 'addlightboxrel_replace');
    
    ?>

    Hi Michiel,
    Here’s the code that I’ve modified to :
    – make the [imagegroup] unique per post (lightbox[id of the post]
    – Have it work if the url of the image is surrounded by ” and not by ‘

    <?php
    /*
    Plugin Name: Add lightbox
    */
    add_filter('the_content', 'addlightboxrel_replace');
    function addlightboxrel_replace ($content)
    {	global $post;
    	$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
      	$replacement = '<a$1href=$2$3.$4$5 rel="lightbox[%LIGHTID%]"$6>';
        $content = preg_replace($pattern, $replacement, $content);
    	$content = str_replace("%LIGHTID%", $post->ID, $content);
        return $content;
    }
    ?>

    I don’t really care about the groups, but I’ve been trying to add the rel=’lightbox’ code automatically by editing upload-js.php.

    However, when I add it to the HREF tags, nothing happens. I click “send to editor” and the code WP spits out still doesn’t have rel=’lightbox’.

    Any help?

    Nevermind! I’m just going to use the “flexible upload” plug-in, much easier!

    I am the same as bryan and cannot see the change in the href. I just want the rel=”lightbox” to show..

    any help or suggestions for some other way.

    Hi
    This is an example page.

    I have actually manually added the rel=”thumbnail” (using this plugin instead) so it works but it does not add it automaticaly which my germworks page does.

    Moderator Andrew Ozz

    (@azaozz)

    WordPress Dev

    Hi, I’m beta-testing a plugin that works similarly to lightbox and can automatically use all image links on a page. There’s no need to add any rel=… etc. Check it out:

    Shutter Reloaded WordPress plugin

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Automatic adding Lightbox rel and group to images in posts?’ is closed to new replies.