Yoast\WP\SEO\Generators\Schema
Article::word_count()
Does a simple word count but tries to be relatively smart about it.
Метод класса: Article{}
Хуков нет.
Возвращает
int
. The number of words in the content.
Использование
// private - только в коде основоного (родительского) класса $result = $this->word_count( $post_content, $post_title );
- $post_content(строка) (обязательный)
- The post content.
- $post_title(строка)
- The post title.
По умолчанию: ''
Код Article::word_count() Article::word count Yoast 20.3
private function word_count( $post_content, $post_title = '' ) { // Add the title to our word count. $post_content = $post_title . ' ' . $post_content; // Strip pre/code blocks and their content. $post_content = \preg_replace( '@<(pre|code)[^>]*?>.*?</\\1>@si', '', $post_content ); // Add space between tags that don't have it. $post_content = \preg_replace( '@><@', '> <', $post_content ); // Strips all other tags. $post_content = \wp_strip_all_tags( $post_content ); $characters = ''; if ( \preg_match( '@[а-я]@ui', $post_content ) ) { // Correct counting of the number of words in the Russian and Ukrainian languages. $alphabet = [ 'ru' => 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя', 'ua' => 'абвгґдеєжзиіїйклмнопрстуфхцчшщьюя', ]; $characters = \implode( '', $alphabet ); $characters = \preg_split( '//u', $characters, -1, \PREG_SPLIT_NO_EMPTY ); $characters = \array_unique( $characters ); $characters = \implode( '', $characters ); $characters .= \mb_strtoupper( $characters ); } // Remove characters from HTML entities. $post_content = \preg_replace( '@&[a-z0-9]+;@i', ' ', \htmlentities( $post_content ) ); return \str_word_count( $post_content, 0, $characters ); }