Remove All Links From WordPress Images Using Functions.php

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on email
Email

I just used the code below for a client’s WordPress site to remove all the links of her uploaded WordPress images from her posts. I am lazy as hell, y’all know that, and the thought of manually editing out the image links of 200+ posts just makes my head reel. So I took the easy way out, using the awesome functions.php. Thought I’d share, someone might find this code equally useful.

So you put this in your theme’s functions.php file:

[javascript]
add_filter( ‘the_content’, ‘attachment_image_link_remove_filter’ );

function attachment_image_link_remove_filter( $content ) {
$content =
preg_replace(
array(‘{]*>}’),
array(‘‘),
$content
);
return $content;
}
[/javascript]

This code assumes that all your images are uploaded in the “normal” folder (wp-content/uploads). Questions? Feel free to ask in the comment section.

7 Responses

    1. This code is made for images hosted on your blog’s server only 😉

      You can change the folder location by replacing this bit:

      wp-content\/uploads

      with the actual location of your image files.

  1. Thanks so much for this mate, you’re a life saver!!!

    Been searching for the last 45 minutes for a fix, but all of the stuff I found was for images that were yet to be uploaded, not images that were already live.

    Thanks again!!

  2. Hello,
    this is the best post i found for that issue!
    But please help me: where do i exactly insert the code above in my functions.php file?? Anywhere in the file, or somewhere specific?
    Thanks in advance to anyone who answers!!

  3. This was so helpful! I’m using a plugin that requires that the images aren’t linked to anything. I was dreading going back through hundreds of blog posts to do that. This saved me!

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT THE GIRL

I wear many hats. But most of all, I am...

STAY CONNECTED

SUBSCRIBE FOR UPDATES

RECENT POSTS

FACEBOOK HAPPENINGS