Last active
February 11, 2022 15:21
-
-
Save wpflames/0a7c3e5bdad3c9d3fada1a19ae246827 to your computer and use it in GitHub Desktop.
Shorten the post title in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php // Don't copy the opening tag | |
| // ========================================================================= | |
| // SHORTEN THE TITLE | |
| // ========================================================================= | |
| function shortenTitle(){ | |
| $thetitle = get_the_title(); | |
| $getlength = strlen($thetitle); | |
| $thelength = 45; | |
| echo substr($thetitle, 0, $thelength); | |
| if ($getlength > $thelength) { | |
| echo "<span class='readmore'>...</span>"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment