• Sponsors


  • How to Cut long title automatically





    Have you already use WPRobot plugins?, especially if you are using Amazon module, sometimes you will got a long Post Title that could make your theme broken (or maybe have a bad look). How to automatically cut this long post title? so our site layout will still normal as usual.

    I have try to search any wordpress plugin that could automatically cut post title into only xx (number) of characters, but i have no luck on it. Long time to search with no result at all.

    Finally i got the answer, but its not from plugin. We can automatically cut long post title with Functions help. It will need a little effort to modify the theme, but it worth to do!. And i am please with it.

    How to automatically cut long post title using functions :

    1. Backup your theme!, just in case you do with wrong way. If you got trouble with it, maybe you can read this post to solve it. Fix Blank Page

    2. Open and edit your functions.php file

    3. Add this functions inside functions.php file

    1. function the_short_title($limit=55,$echo=1,$title=''){
    2. if (empty($title)){
    3. $title = the_title('','',false);
    4. }
    5. if (strlen($title)<=$limit){
    6. }else{
    7. $title = substr_replace(the_title('','',false),'...',$limit);
    8. }
    9. if ($echo==1){
    10. echo $title;
    11. }else{
    12. return $title;
    13. }
    14. }

    $limit=55 is the max character.

    4. Open your index.php file or home.php file. (open the file that will control your theme).  The original script to show your Post title is like this :

    1. <?php the_title(); ?>

    It will show all of the title, if the title has 100 words on it, all of them will shown as complete title. Change that script into this code :

    1. <?php the_short_title(55); ?>

    With using that script, your post title will show only for 55 characters, and cut the rest of it. Change the 55 number into your own desired number (depends on your theme needs)

    That’s all. With add new functions and replace the original script that call the post title, this will answer your question about How to cut long title automatically. If you got error message, and occurs blank page, read this post.

    Author: cahyo on June 30, 2011
    Category: Tips
    Tags: , , , , , , , , , , ,

    Facebook comments:

    1 response to “How to Cut long title automatically”

    Leave a Reply


    1 + 2 =

    Last articles