I have been using wordpress for my projects. For my homepage of the site I need to display limited text from the post content and the content contains images as well. To display the 100 text i have used substr function of php. What happens here is that the text as well as image is dispalayed. I want to display only the text. Is there any way or plugin to do so?

Any help is appreciated. Thanks in advance

2 Answers 2


use strip_tags + substr

substr( strip_tags( get_the_excerpt() ),0,235);
  • Thank you Satish .. Actually I know about strip_tags php function but did not think of using it :P. It worked for me..
    – user478
    Commented May 23, 2011 at 5:56
  • Use mb_substr() to avoid broken UTF-8 characters.
    – fuxia
    Commented May 23, 2011 at 12:02
  • problem is, that this will still contain stuff like [caption ... ][/caption] Commented Jan 8, 2014 at 13:45

If you're in the loop, then use wp_trim_excerpt() function, which will return an extract of 55 words.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     // Your HTML code...
     <p><?php echo wp_trim_excerpt(); ?></p>
     // Go on with more HTML (if you want to)
<?php endwhile; endif; ?>

Otherwise, if you're not in the loop then try using the excerpt field that is set from the post edit screen.

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.