Feb
16
2009
Removing Images from a WordPress Post: Redux
I wanted to remove the images from a WordPress post to give me more control of how I could layout the design for the front page of a website. After doing some messing around and failing, I finally found a great post by Chris Shuld which had an amazing little piece of code that solved my problem. I just had to make a few modifications to it.
<?php $content = get_the_content(); $postOutput = preg_replace('/<img[^>]+./','', $content); echo $postOutput; ?> |



THANK YOU!!!! I have never commented on a blog, but this little piece of code kicked ass!
Hi. Your code really helps me! Just a question. It looks like displaying “plain” text. Do you know how can I get the html code in the content like p, a, h3, etc tags?
Just use the following:
wplistcategories(‘usedescfor_title=0′);
print("wp_list_categories('use_desc_for_title=0'); ");
Do i put this code in the page or in the functions?
I’m trying to use this with an excerpt function, here is what I have:
The excerpt never showed an image, but because of the image placement it didn’t show any text either.
Now it’s only showing the 1st letter of the post.
Take a look at this post:
http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
where i must add the code? wp_config.php?
You can add that code directly to the file where you want to call the content.
Thank you!
No my search finaly ends.
I’m sorry, I send a comment about this subject and then see this page. thanks lot
Oh, your script is pretty useful ,Thank you so much!!:DDD
Perfect!! Thanks
Hey…this is really easy way to do this. Using filter hook.
And if you want you can use conditional tags if u want to display content without images just in front_page or category archive etc…
Awesome. That’s some nice code. I just started getting into filters and actions and they are great.
Please explain how to use this function. Sorry I’m a newbie
Thanks.
This is awesome code, We will be making this into a plug in to disable images in our blogs. Great work!
I thing add_filter in the function is better
This was VERY useful, thanks so much! I used this in conjunction with a function to let me place images:
then I just stick in a
where I want images to appear from the post.
thanks so much ! i need it because i using wordpress for e commercer