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

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

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

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.