How to limit the characters on post title
Sometime, especially news type of contents, titles of post can be long and mess your neat layout. This is how to limit the post titles.
1. Copy and paste this code in your function.php
<?php function limit_title($title, $n){ if ( strlen ($title) > $n ){ echo substr(the_title($before = ”, $after = ”, FALSE), 0, $n) . ‘…’; }else{ the_title(); } } ?>
2. To use this function simply change the number of characters and paste it to your template file in where you want to limit the characters on post title.
<?php limit_title($post->post_title, 30); ?>
Thanks to WP Geek for this code
3 Comments
Husien adel on December 24th, 2009
thanks a lot Takashi , I was searching on that trick for a wp client theme modification and found it , Nice blog ..Keep Going Man .
BTW i discover your Blog Via My friend Google :D
alex-ye on July 5th, 2010
thank you very much thats very helpfull !!!

















wpthemes on December 14th, 2009
thanks for code