Skip to content

Instantly share code, notes, and snippets.

@ElmahdiMahmoud
Last active October 12, 2015 19:38
Show Gist options
  • Save ElmahdiMahmoud/4077123 to your computer and use it in GitHub Desktop.
Save ElmahdiMahmoud/4077123 to your computer and use it in GitHub Desktop.
wp: Limit Post Title by amount of 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