Skip to content

Instantly share code, notes, and snippets.

@omurphy27
Created February 27, 2013 04:20
Show Gist options
  • Save omurphy27/5045049 to your computer and use it in GitHub Desktop.
Save omurphy27/5045049 to your computer and use it in GitHub Desktop.
Wordpress PHP Shorten the_title
<?php
// Shorten the Wordpress Title
// how to shorten the title in wordpress
echo substr(the_title('', '', FALSE), 0, 40);
// check here for more info: http://wordpress.org/support/topic/how-to-limit-character-on-title
// This is how i shorten the title and make sure to append '...' on the end of it:
// Make sure to define this guy first:
$title_string = strlen(get_the_title());
// then put the following down below where you want the title
echo substr(the_title('', '', FALSE), 0, 50) ;
if ( $title_string > 50 ) {
echo '...' ;
} else {
echo ' ';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment