Last active
July 24, 2020 20:09
-
-
Save celsofabri/615d6622418071b57012b48e0d301d8f to your computer and use it in GitHub Desktop.
Word title limit 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
function limit_word_count($title) { | |
$len = 5; //change this to the number of words | |
if (str_word_count($title) > $len) { | |
$keys = array_keys(str_word_count($title, 2)); | |
$title = substr($title, 0, $keys[$len]); | |
} | |
return $title; | |
} | |
add_filter('the_title', 'limit_word_count'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment