WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i've implemented a jQuery gallery for displaying several images within a post. the problem is that the_content(); also displays the post image. any ideas how to filter it? thanks

share|improve this question
maybe you can give us a little more to work with? Are you just attaching the images to the post or are you actually putting them in the post content? – eileencodes Mar 1 '11 at 14:58
i've attached the images directly to the post (i'm having the [gallery] tag in my content) - but as attaching images has to be easy for our customer, the tag needs to remain in the content - that's why i need to filter it at the frontend. thanks – Fuxi Mar 1 '11 at 15:08
you would still attach images per post just leave out gallery short code and write a get_posts query for attachments. See codex.wordpress.org/Template_Tags/get_posts as the post_type would be attachments and then use wp_get_attachment_image (codex.wordpress.org/Function_Reference/wp_get_attachment_image) and manually build your gallery in the theme. The only difference would be the lack of [gallery] in your post content. – eileencodes Mar 1 '11 at 15:53
up vote 9 down vote accepted

you can add a filter to the_content hook to strip the images

something like:

add_filter('the_content', 'strip_images',2);

function strip_images($content){
   return preg_replace('/<img[^>]+./','',$content);
share|improve this answer
is it possible to have this to work only on certain pages and not on other pages (or categories?) – alemur Apr 4 '12 at 14:40
Yep, just check in the function if its the right page using Conditional Tags codex.wordpress.org/Conditional_Tags – Bainternet Apr 4 '12 at 14:45

This is better:

<?php echo strip_shortcodes(wp_trim_words( get_the_content(), 80 )); ?>

Change 80 to whatever count words.

share|improve this answer
Please explain why that could solve the problem. – toscho Mar 18 '13 at 23:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.