How to Automatically Remove Links from WordPress Images

How to Automatically Remove Links from WordPress Images


In most cases (unless your theme is set up otherwise), you will find that images in a WordPress post are automatically linked to an image file page. Some may like that. Others, however, may not.

If you happen to be one that doesn’t, then there’s a quick and simple fix to this issue. You can place the following code (found at stackexchange) in your functions.php file. (Appearance > Editor > Theme Functions – functions.php)

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

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;
 }

And that’s it.

If you would like to make your own simple plugin for this task, you can learn how to do that here.

Photo: Broken Chain from BigStock

Tags: