remove image link wordpress

By defualt when you add image from gallery the link also added to the image.A link to image can be remove easy writing small code into function.php or creating plugin.

Here is code for how to remove links from images

add_filter('the_content', 'remove_images_from_post_page');

function remove_images_from_post_page($content){

  $content = preg_replace('/]*>]*)><\/a>/im', '', $content);

  return $content;
}

 
 add_shortcode( 'gallery', 'remove_images_links_gallery' );

function remove_images_links_gallery($attr) {

    global $post, $wp_locale;

    $output = gallery_shortcode($attr);
    $output = preg_replace('/]*>]*)><\/a>/im', '', $output);      

    return $output;

}

Leave a Reply

Your email address will not be published. Required fields are marked *