During my work as a wordpress theme coder I came across that there are request for a function on how to limit the post titles. So here you are the code and hope that it will be useful for you:
Open functions.php in your theme and copy/paste this code:
<?php function limit_title($title, $n){
if ( strlen ($title) > $n )
{
echo substr(the_title($before = ”, $after = ”, FALSE), 0, $n) . ‘…’;
}
else { the_title(); }
}
?>
Then just put this function where you want in your wordpress theme templates:
<?php limit_title($post->post_title, 30); ?>
Note:
2 Responses for "How to limit WordPress posts title"
Thanks for this tut
Hi,
This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post.
Thanks!
Mamunur Rasid
oDesk Outsourcing Provider.
Leave a reply