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
That’s really helpful. I just hope I can grasp what all that coding means 🙂
By the way, I mentioned you in this post: http://pepperrific.com/2012/02/smells-like-teen-californication/
this post really helps me, but how about if image location from the other site…
can we use your methode like above…
i want to apply your way to my blog samsuhidayat.com
thank you
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.
Thank you SO much! This really helped me out.
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!!
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!!
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!