Last active
October 12, 2015 19:38
-
-
Save ElmahdiMahmoud/4077134 to your computer and use it in GitHub Desktop.
wp: Limit Post Content by Amount of Characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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