Programming, WordPress

Display first 8 words from the Sentence

My client asked  me to display only 8 words of the long title of the post. So, to fulfill his requirement,  I just count the number of words in  the title and if the title consist of more than 8 words, I extract 8 words from the title and displayed it , otherwise displayed the title as it is.

Steps 1 :   Create function that returns the first 8 words from the title/sentence, place it anywhere in your function.php or helpers.php files

Step 2 : Count the number of words in the title and use the function in step 1, to extract 8 words form the title. If the title has less than 8 words, do nothing just display the title.

Hits: 2