WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Automatic adding Lightbox rel and group to images in posts? (11 posts)

  1. Michiel
    Member
    Posted 7 years ago #

    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!

  2. Michiel
    Member
    Posted 7 years ago #

    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.

  3. alakhnor
    Member
    Posted 7 years ago #

    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);
    }
  4. manumanu
    Member
    Posted 7 years ago #

    sir, is this still in development?

  5. Michiel
    Member
    Posted 7 years ago #

    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');
    
    ?>
  6. Mdkart
    Member
    Posted 7 years ago #

    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;
    }
    ?>
  7. bryan868
    Member
    Posted 7 years ago #

    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?

  8. bryan868
    Member
    Posted 7 years ago #

    Nevermind! I'm just going to use the "flexible upload" plug-in, much easier!

  9. germ
    Member
    Posted 7 years ago #

    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.

  10. germ
    Member
    Posted 6 years ago #

    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.

  11. Andrew Ozz
    WordPress Dev
    Posted 6 years ago #

    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:
    http://www.laptoptips.ca/projects/wp-shutter-reloaded/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags