Skip to content

Instantly share code, notes, and snippets.

@tayvano
Created January 21, 2017 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tayvano/2b8693f147df1a6d4c8807e7fdbd0ff0 to your computer and use it in GitHub Desktop.
Save tayvano/2b8693f147df1a6d4c8807e7fdbd0ff0 to your computer and use it in GitHub Desktop.
function limit_char($limit, $source=null) {
global $post;
($source) ? '<p>'.$source.'</p>' : $source = '<p>'.get_the_excerpt().'</p>';
$read_more = '... <a href="'. get_permalink($post->ID) . '" class="more-link" title="Read '.get_the_title($post->ID).'">Read more</a>';
$limited = strlen($source) > $limit ? substr($source,0,strpos($source,' ',$limit)) . $read_more : $source;
echo $limited;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment