Remove anchor Links from attachment Images in WordPress

In WordPress website if you see that attachment images in a post contents are automatically linked to an image file individual page and dont want it.
then in WOrdpress a quick and simple fix for Remove anchor Links from attachment Images in WordPress. just copy paste the following code in your functions.php file. (Appearance > Editor > Theme Functions – functions.php)

add_filter( 'the_content', 'wdo_remove_attachment_image_link' );
function wdo_remove_attachment_image_link( $content ) {
	$content = preg_replace(array('{<a(.*?)(wp-att|wp-content\ uploads)[^="">]*><img}','{ wp-image-[0-9]*"="">}'),array('<img','">'),$content);
	return $content;
}
</img','"></img}','{></a(.*?)(wp-att|wp-content\>

Other Solutions is Disable Click on Image by CSS

How to disable a link using CSS?

.content a img.size-full{pointer-events: none; cursor: default;}

 

Scroll to Top