Wordpress Hack the_content() display xx or 300 words only
Many developer ask, how to display short description or 300 words on post, on listing page so can display many posts on single page, if user like to read that post, he/she go ahead and click on details link to read fully post.
for it you need to use substr like this as below
<?php echo substr(strip_tags($post->post_content), 0, 250);?>
you can change ‘250′ with any numbers of words you want to display on listing page. or any place














November 3rd, 2008 at 5:51 am
Great, thanks its really simple to do.. i was working to find a solution from a long time
Yash
March 29th, 2009 at 12:14 am
Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language
See you!
Your, Raiul Baztepo
April 22nd, 2009 at 1:29 pm
An other way to do it
‘, ‘]]>’, $content);
echo substr(strip_tags($content), 0, 250).’…’ ;?>
April 22nd, 2009 at 1:30 pm
An other way to do it
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(’the_content’, $content);
$content = str_replace(’]]>’, ‘]]>’, $content);
echo substr(strip_tags($content), 0, 250).’…’ ;
May 7th, 2009 at 12:38 pm
thanks
September 9th, 2009 at 8:24 am
Hi! Is there a way to get only the first line of the post content?
Thx in advance!
September 9th, 2009 at 8:30 am
i guess, no untill you assign special value of that line..
like
1st line #
#= let system know that 1st line end
April 20th, 2010 at 4:00 am
this is great, only creates a bug where if you have an image with caption in your post, you will see what looks like vB tags for the caption in your excerpt. example:
[caption id="attachment_116" align="alignnone" width="300" caption="this is a caption"][/caption]
May 10th, 2010 at 12:57 pm
wow
thanks!
helped me alot!
May 14th, 2010 at 4:47 am
can help me how to hack values the_content() from wordpress command?
June 19th, 2010 at 4:15 am
This gives you the first X characters, not words…
August 11th, 2010 at 10:51 am
Very Nice Trick
August 17th, 2010 at 6:29 am
It’s a good resource. But I don’t know how to use it and how to apply it in my theme!
Thanks if have any help! 
August 17th, 2010 at 7:43 am
you need to edit your themes pages, replace the_content(); to < ?php echo substr(strip_tags($post->post_content), 0, 250);?>
August 19th, 2010 at 12:57 pm
WP User: This function will get $limit of words from $content or the get_the_content() method.
Just from the top of my head, might need some fixing.
<?php
function get_word_limit( $limit = 10, $content = ” ) {
if( empty( $content ) ) {
$content = get_the_content();
}
$segments = explode(’ ‘, strip_tags( html_entity_decode( $content ) ) );
$return = ”;
for( $i = 0; $i < $limit; $i++ ) {
$return .= $segments[ $i ];
}
unset( $segments );
return $return;
}
SAN: Using will function better as it removes tags, decodes any HTML enitities like .
August 21st, 2010 at 11:48 am
doesnt seem to work
$cntnt = the_content(); substr(strip_tags($cntnt, “img”), 0, 200);
Its just not working at all
August 25th, 2010 at 3:25 pm
@bluepicaso,
You cannot use $cntnt=the_content(). Instead of the_content(), use get_the_content() or $post->post_content. the_content() always prints the content inside.
Best.
November 5th, 2010 at 3:35 pm
Thanks I have develop on my site.
December 28th, 2010 at 8:18 am
Thanks this is a great help.
January 1st, 2011 at 12:40 am
the image is not showing. any help?
April 15th, 2011 at 3:43 pm
O my lord, it’s so simple… Thank you!!!