1

When Upload images from Editor and publish the post, I see for all images have link. How can remove it

3 Answers 3

2

This should do the trick. The filter will check for images and removes the a (link) tag. Just add it to your theme's functions.php:

add_filter( 'the_content', 'attachment_image_link_remove_filter' );
 function attachment_image_link_remove_filter( $content ) {
  $content =
  preg_replace(
  array('{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
  '{ wp-image-[0-9]*" /></a>}'),
  array('<img','" />'),
  $content
  );
  return $content;
   }
3
  • 1
    So you copied the code from the answer I suggested. Please don't do that, because generally duplicate content should be prevented. Commented Dec 1, 2014 at 14:47
  • Since I'm not allowed to simply post links to other content, I think this is the most proper anwser to the question. Better then none anwserd questions if you ask me. Commented Dec 1, 2014 at 15:24
  • You can post links in comments, if you are not able yet earn some reputation. Commented Dec 1, 2014 at 15:39
1

I tried the above solution and it seemed to work but on viewing the source code I found stray link closing tags: </a>

I found this solution which works:

function attachment_image_link_remove_filter($content) {
    $content = 
        preg_replace(
            array('{<a[^>]*><img}', '{/></a>}'),
            array('<img', '/>'), 
            $content
        );
    return $content;
}
add_filter('the_content', 'attachment_image_link_remove_filter');

Thanks to @noman for answering this post

0

When inserting the image via the »Media Library« Modal, after clicking »Add Media«, select »None« for »Link To« under »Attachment Display Settings« section. To remove it for already linked images, click on the image and then press the »Remove link« button.

6
  • ok, But old post how delete url for it ?
    – AbuKotsh
    Commented Dec 1, 2014 at 13:48
  • see 2nd part of the answer @KotshMan Commented Dec 1, 2014 at 13:51
  • 2
    But i have more than 2000 post !!!
    – AbuKotsh
    Commented Dec 1, 2014 at 13:53
  • Brief outline: loop through posts (content) regex for img tags inside a tags and remove the a tags. Take a look around, there have been similar questions asked before. @KotshMan Commented Dec 1, 2014 at 13:58
  • how can do that ?? so that is reson to post my question
    – AbuKotsh
    Commented Dec 1, 2014 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.