1

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

1

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;
   }
  • 1
    So you copied the code from the answer I suggested. Please don't do that, because generally duplicate content should be prevented. – Nicolai Dec 1 '14 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. – john23klipp Dec 1 '14 at 15:24
  • You can post links in comments, if you are not able yet earn some reputation. – Nicolai Dec 1 '14 at 15:39
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.

  • ok, But old post how delete url for it ? – mak man Dec 1 '14 at 13:48
  • see 2nd part of the answer @KotshMan – Nicolai Dec 1 '14 at 13:51
  • 1
    But i have more than 2000 post !!! – mak man Dec 1 '14 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 – Nicolai Dec 1 '14 at 13:58
  • how can do that ?? so that is reson to post my question – mak man Dec 1 '14 at 14:00
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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