Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created January 4, 2012 16:41
Show Gist options
  • Save ramseyp/1560867 to your computer and use it in GitHub Desktop.
Save ramseyp/1560867 to your computer and use it in GitHub Desktop.
Truncate WordPress post title
<?php
/**
* Truncate WordPress post title
* @author Pat Ramsey
* @link
*
* @param $title, $limit
*/
function s25_trunc_title( $limit ) {
global $post;
$title = get_the_title ( $post->ID );
if ( strlen( $title ) > $limit ) {
$title = substr ( $title, 0, $limit ) . '...';
}
return $title;
}
//
// usage: echo s25_trunc_title($limit);
//
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment