In the first two articles in this series, we took a high-level look at what unit testing is and how to apply it in the context of plugin development.
As a PHP application, WordPress is usually deployed by a very old method: uploading files via FTP. We have some deployment tools, but they often requires some type of Ruby skill. For example, one popular, powerful tool is Capistrano, but it’s also very heavy with many Ruby/Rails related features.
Straight from the WP Codex there is a command to trim the word count on text – commonly used for controlling the_excerpt length to customise ‘read more’ and ‘introduction’ type on a page.
$trimmed = wp_trim_words( $text, $num_words = 55, $more = null );
The above example will trim a
$text variable to 55 words and have nothing trailing.
Tip for new comers: Using wp_trim_words() on the_title returns an array and not a string, so it doesn’t work with.
Instead you are likely looking for:
echo wp_trim_words( get_the_title(), 55, null );