function add_rel_lightbox($content)
    {

    	/* Find internal links */

    	//Check the page for link images direct to image (no trailing attributes)
    	$string = '/<a href="(.*?).(jpg|jpeg|png|gif|bmp|ico)"><img(.*?)class="(.*?)wp-image-(.*?)" \/><\/a>/i';
    	preg_match_all( $string, $content, $matches, PREG_SET_ORDER);

    	//Check which attachment is referenced
    	foreach ($matches as $val)
    	{
    		$slimbox_caption = '';

    		$post = get_post($val[5]);
    		$slimbox_caption = esc_attr( $post->post_content );

    		//Replace the instance with the lightbox and title(caption) references. Won't fail if caption is empty.
    		$string = '<a href="' . $val[1] . '.' . $val[2] . '"><img' . $val[3] . 'class="' . $val[4] . 'wp-image-' . $val[5] . '" /></a>';
    		$replace = '<a href="' . $val[1] . '.' . $val[2] . '" rel="lightboxp[glry]" title="' . $slimbox_caption . '"><img' . $val[3] . 'class="' . $val[4] . 'wp-image-' . $val[5] . '" /></a>';
    		$content = str_replace( $string, $replace, $content);
    	}

    	return $content;
    }

    /* Filter Hook */
	add_filter('the_content', 'add_rel_lightbox', 2);
    add_filter('acf_the_content', 'add_rel_lightbox', 2);

 

Geef een reactie 0