There are several situations were a shorter text version on your website is necessary: Post summaries for result pages or just for the page’s META description (of course it’s better to write a unique description). The regular PHP function “substr()” will shorten your text to a given length without a check if the text will end in a middle of a word.

I’m using this custom PHP function to shorten my text blocks on most of my non-WordPress websites:

The function works like the sub_str() function in PHP, but without to break all the words in pieces. The value for the $length is the maximum number of characters the function can return (it depends on the length of the last checked word).

Pin It on Pinterest

Share This

Share this post with your friends!