| | 1841 | * Creates a short version of the text, according to the word limit. |
| | 1842 | * |
| | 1843 | * @since 3.2.0 |
| | 1844 | * |
| | 1845 | * @param string $text The text to trim. |
| | 1846 | * @param int $length Optional. Word limit. |
| | 1847 | * @param string $more Optional. The string to replace the text which was left out. |
| | 1848 | * @return string Trimmed text. |
| | 1849 | */ |
| | 1850 | function wp_trim_words( $text, $length = 55, $more = '[...]' ) { |
| | 1851 | $words = preg_split( "/[\n\r\t ]+/", $text, $length + 1, PREG_SPLIT_NO_EMPTY ); |
| | 1852 | if ( count($words) > $length ) { |
| | 1853 | array_pop($words); |
| | 1854 | $text = implode(' ', $words); |
| | 1855 | $text = $text . $more; |
| | 1856 | } else { |
| | 1857 | $text = implode(' ', $words); |
| | 1858 | } |
| | 1859 | return $text; |
| | 1860 | } |
| | 1861 | |
| | 1862 | /** |
| 1867 | | $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); |
| 1868 | | if ( count($words) > $excerpt_length ) { |
| 1869 | | array_pop($words); |
| 1870 | | $text = implode(' ', $words); |
| 1871 | | $text = $text . $excerpt_more; |
| 1872 | | } else { |
| 1873 | | $text = implode(' ', $words); |
| 1874 | | } |
| | 1889 | $text = wp_trim_words($text, $excerpt_length, $excerpt_more); |