Programming, WordPress

Display limited words from the title

Does long title bother you? Are you trying to find solution to trim the title and display some limited words ?

Let’s say if your title is longer than 8 words, you want to display first 8 words and ignore the rest. Solution, to trim the title could be count the number of words in  the title and if the title consist of more than 8 words,  extract 8 words from the title and display 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: 12