Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
1  
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
add comment

2 Answers

up vote 6 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?) –  Akmur 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
add comment

This is better:

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

Change 80 to whatever count words.

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

Your Answer

 
discard

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.