WordPress

Content Image popup

This code will make images on the content popup on click using the fancy-box library. Add the code to the functions.php file.

function prefix_content_gallery( $content ) {
    global $post;
    $pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
    $replacement = '<a$1href=$2$3.$4$5 data-fancybox="gallery" title="'.$post->post_title.'"$6 style="border:none;"><img$1src=$2$3.$4$5 $6></a>';
    $content     = preg_replace( $pattern, $replacement, $content );
    return $content;
}
add_filter( 'the_content', 'prefix_content_gallery', 99);