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)

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