I am following this tutorial â “Display Your Popular Posts In WordPress Without A Plugin” and want to limit the max number of characters in the title that are displayed. Also, why is the thumbnail, at times, smaller than the number I define in the php?
Leave a Reply
You must be logged in to post a comment.
first add this function to your functions.php file
then before the loop of the code you linked add this line to hook the above function:
and after the loop remove this filter:
and just change
$max = 20;
to whatever you want.You can use this bit to limit the number of characters displayed and append an ellipsis.
In this particular example I’ve set it to trunicate at 38 characters and only display the ellipsis if the title was trunicated. And regardless of the length, display the full title on the single_post page.
I’ve improved the @Bainternet answer to only display
...
when the title is longer than$max
:Then you can hook like this: