Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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