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' );
  • my_recent_post() is not a generic WordPress function; please post the code of that function.
    – Michael
    Aug 10, 2012 at 14:29
  • DAP! Sorry, I meant to do that. Aug 10, 2012 at 14:36

1 Answer 1


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.

  • let me know if this isn't working..
    – Amit Kosti
    Aug 10, 2012 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! Aug 10, 2012 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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