• Several contributors have added image(s) to hundreds of posts on our blog. It’s been requested that when a post image is clicked, it pops in a lightbox with the full-size image. I’ve piece-mailed together some code to find the image-link in each post, add rel=”lighbox[post-slug]” to hook in a lightbox, and the only challenge yet is to change the attachment image to point to the full-size image so the lightbox knows what to do.
    Basically, I am unable to get the attachment-image link/id dynamically.
    here is the code I have so far:

    <?php
    /*
    change all post image links to link to larger image
    */
    add_filter( 'the_content', 'attachment_image_link_change_filter' );
    function attachment_image_link_change_filter( $content ) {
    
    $content = preg_replace(
     	array('{<a(.*?)[^>]*><img}','{wp-image-[0-9]*" /></a>}'),
      	array('<a href="%IMGLINKLG%"><img','" /></a>}'),
    	$content);
     $content = str_replace("%IMGLINKLG%", wp_get_attachment_url($id), $content);
        return $content;
    }
    
    /*
    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$1  rel="lightbox[%LIGHTID%]" title="%TITLE%" href=$2$3.$4$5$6>';
        $content = preg_replace($pattern, $replacement, $content);
    	$content = str_replace("%LIGHTID%", $post->post_name, $content);
    	$content = str_replace("%TITLE%", $post->post_title, $content);
        return $content;
    }
    ?>

    wp_get_attachment_url($id) is the piece that needs to change but not sure what else to do….

Viewing 1 replies (of 1 total)
  • just ran into the EXACT same issue… we have over 1000 posts…. it’d take forever to edit each post manually…

    is there anyway to dynamically change the url images link to to be the full size image?

    thanks in advance!

Viewing 1 replies (of 1 total)
  • The topic ‘dynamically linking post images to full size’ is closed to new replies.