Short Page Title

You can use this text to make a short page title.

<?php
$thetitle = get_the_title(); /* or you can use $post->post_title; */
$getlength = strlen($thetitle);
$thelength = 25;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo “…”;
?>

Or you can do add this to your functions.php file.

function max_title_length($title){
$max = 20;
return substr( $title, 0, $max ). ” &hellip;”;
}

and then use this call wherever you want

<?php echo max_title_length(get_the_title()); ?>

 

 

Leave a Reply