YPSA Webmaster's Blog

Skip to content Skip to sidebar

Truncate WordPress Post Titles with PHP

First open your index.php or the file location where you want to truncate the title. Then paste the following code to replace your the_title tag.

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

About the author

Abdullah Al Shakir

I am a web developer and graphics designer have been working in YPSA as webmaster since 2006. I am expert in XHTML, CSS, JavaScript and PHP programming. I am Wordpress theme and plugin developer. I am a father and husband living in Bangladesh.

You may also like

Leave a Reply