Gallery – custom html for inserting images

In cleaner-gallery.php make changes to the cleaner_gallery_plugin_gallery_image function that starts on line 122 and ends on line 151.

What we are doing is replacing href with data-href in the two instances that output the html with the image attributes.

function cleaner_gallery_plugin_gallery_image( $image, $id, $attr, $instance ) {

    /* If the image should link to nothing, remove the image link. */
    if ( 'none' == $attr['link'] ) {
        $image = preg_replace( '/<a.*?>(.*?)<\/a>/"https://wordpress.stackexchange.com/questions/23763/,"$1', $image );
    }

    /* If the image should link to the 'file' (full-size image), add in extra link attributes. */
    elseif ( 'file' == $attr['link'] ) {
        $attributes = cleaner_gallery_link_attributes( $instance );

        if ( !empty( $attributes ) )
            $image = str_replace( '<a href="https://wordpress.stackexchange.com/questions/23763/,"<a{$attributes} data-href=", $image );
    }

    /* If the image should link to an intermediate-sized image, change the link attributes. */
    elseif ( in_array( $attr["link'], get_intermediate_image_sizes() ) ) {

        $post = get_post( $id );
        $image_src = wp_get_attachment_image_src( $id, $attr['link'] );

        $attributes = cleaner_gallery_link_attributes( $instance );
        $attributes .= " data-href="{$image_src[0]}"";
        $attributes .= " title="" . esc_attr( $post->post_title ) . """;

        $image = preg_replace( '/<a.*?>(.*?)<\/a>/"https://wordpress.stackexchange.com/questions/23763/,"<a{$attributes}>$1</a>", $image );
    }

    /* Return the formatted image. */
    return $image;
}

error code: 523