Last active
October 12, 2015 19:38
-
-
Save ElmahdiMahmoud/4077123 to your computer and use it in GitHub Desktop.
wp: Limit Post Title 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_title($num) { | |
$limit = $num+1; | |
$title = str_split(get_the_title()); | |
$length = count($title); | |
if ($length>=$num) { | |
$title = array_slice( $title, 0, $num); | |
$title = implode("",$title)."..."; | |
echo $title; | |
} else { | |
the_title(); | |
} | |
} | |
?> | |
// Usage <?php short_title(10); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment