i wanna show 20 chars of the_content

i tried this but doesn't work for me .

<?php $content = '';
$content = the_content();
$count_content = strlen($content);
   if($count_content > 20 ) {
     $description = substr($content, 0,20,'UTF-8');
     echo $description ;
   else {
     echo $content;
  • Have you verified that $content contains what you think it does? How about running var_dump() on it?
    – Dan
    Apr 17, 2014 at 17:45

1 Answer 1


Check out the Wordpress Codex reference page for the_excerpt() as it is a built-in way of doing what you're looking to accomplish:

EDIT: it also has an example for shortening the excerpt beyond the default length.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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