Skip to content

Instantly share code, notes, and snippets.

@ElmahdiMahmoud
Last active October 12, 2015 19:38
Show Gist options
  • Save ElmahdiMahmoud/4077134 to your computer and use it in GitHub Desktop.
Save ElmahdiMahmoud/4077134 to your computer and use it in GitHub Desktop.
wp: Limit Post Content by Amount of Characters
<?php
function short_content($num) {
$limit = $num+1;
$content = str_split(get_the_content());
$length = count($content);
if ($length>=$num) {
$content = array_slice( $content, 0, $num);
$content = implode("",$content)."...";
echo '<p>'.$content.'</p>';
} else {
the_content();
}
}
?>
// Usage <?php short_content(20);?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment