Truncate wordpress title


/ Published in: PHP
Save to your folder(s)

Paste the following code to replace your the_title tag in the loop. Make sure you edit the $thelength variable from 25 to the character count of your need.


Copy this code and paste it in your HTML
  1. <a href="<?php the_permalink() ?>">
  2. <?php
  3. $thetitle = $post->post_title; /* or you can use get_the_title() */
  4. $getlength = strlen($thetitle);
  5. $thelength = 25;
  6. echo substr($thetitle, 0, $thelength);
  7. if ($getlength > $thelength) echo "...";
  8. ?>
  9. </a>

URL: http://codezroz.com/php/truncate-wordpress-titles-with-php/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.