Whereas engaged on our shopper’s web site, the design’s width wouldn’t enable us to maintain the lengthy titles to be displayed on the homepage. After looking the net for choices, we got here throughout a number of plugins that may truncate WordPress titles, however they’d do it sitewide whereas we solely wished it on the homepage. On this article, we are going to share with you how one can truncate WordPress Publish Titles with PHP.
First open your index.php or the file location the place you need to truncate the title. Then paste the next code to interchange your the_title tag.
Ensure you edit the $thelength variable from 25 to the character rely of your want. You would need to estimate the rely in your theme design. The code provides the size variable after which use the conditional tag to see if the title size matches our desired size. Whether it is longer, then the code provides ‘…’ in entrance. More often than not, you’ll use this solely on particular areas the place the width is fastened within the theme.
*This can be a good code to have as a theme designer*.