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.

Is there any way to not get the images with get_the_excerpt()? I am using a my_recent_post() function to pull posts onto the home page and I don't need to have it pull the images within the posts, just some of the text.

Here's the function that I am using:

function my_recent_post()
 {
  global $post;
  $html = "";
  $my_query = new WP_Query( array(
       'post_type' => 'post',
       'posts_per_page' => 3
  ));

  if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();

       $html .= "<div class='item'><a href=\"" . get_permalink() . "\"><span>" . get_the_date() . "</span></a>" . get_the_post_thumbnail() . "
       " . get_the_excerpt() . "</div> <div class='clear'></div>";

  endwhile; endif;

  return $html;
}
add_shortcode( 'news', 'my_recent_post' );
share|improve this question
    
my_recent_post() is not a generic WordPress function; please post the code of that function. –  Michael Aug 10 '12 at 14:29
    
DAP! Sorry, I meant to do that. –  ultraloveninja Aug 10 '12 at 14:36
add comment

1 Answer

Use the_excerpt(); wordpress function to show only text. That function will filter out some html tags such as <img> , <a>. A useful alternative to show only plain text.

Note -

The the_excerpt() function internally uses get_the_excerpt() to get excerpt and return a new string by filtering tags such as <img>, <a> tags. It also wrap that string into <p> tags.

share|improve this answer
    
let me know if this isn't working.. –  amit Aug 10 '12 at 15:00
    
Yep, looks like it's working. I also have the Advanced Excerpt plugin installed, so I was able to weak it with that. I'll keep messing with it a little more and if I hit a snag, I'll let you know. Thanks for the input! –  ultraloveninja Aug 10 '12 at 15:45
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.