When Upload images from Editor and publish the post, I see for all images have link. How can remove it
3 Answers
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;
}
-
1So 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
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
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.
-
-
-
2
-
Brief outline: loop through posts (content) regex for
img
tags insidea
tags and remove thea
tags. Take a look around, there have been similar questions asked before. @KotshMan Commented Dec 1, 2014 at 13:58 -