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 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

share|improve this question

2 Answers 2

use strip_tags + substr

substr( strip_tags( get_the_excerpt() ),0,235);
share|improve this answer
    
Thank you Satish .. Actually I know about strip_tags php function but did not think of using it :P. It worked for me.. –  user478 May 23 '11 at 5:56
    
Use mb_substr() to avoid broken UTF-8 characters. –  toscho May 23 '11 at 12:02
    
problem is, that this will still contain stuff like [caption ... ][/caption] –  spankmaster79 Jan 8 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.

share|improve this answer

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.