WPSEO_Replace_Vars::retrieve_excerpt
Retrieve the post/page/cpt excerpt for use as replacement string. The excerpt will be auto-generated if it does not exist.
Метод класса: WPSEO_Replace_Vars{}
Хуков нет.
Возвращает
string|null.
Использование
// private - только в коде основоного (родительского) класса $result = $this->retrieve_excerpt();
Код WPSEO_Replace_Vars::retrieve_excerpt() WPSEO Replace Vars::retrieve excerpt Yoast 28.4
private function retrieve_excerpt() {
$replacement = null;
$locale = get_locale();
// Japanese doesn't have a jp_JP variant in WP.
$limit = ( $locale === 'ja' ) ? 80 : 156;
// The check `post_password_required` is because excerpt must be hidden for a post with a password.
if ( ! empty( $this->args->ID ) && ! post_password_required( $this->args->ID ) ) {
if ( $this->args->post_excerpt !== '' ) {
$replacement = wp_strip_all_tags( $this->args->post_excerpt );
}
elseif ( $this->args->post_content !== '' ) {
$content = strip_shortcodes( $this->args->post_content );
$content = wp_strip_all_tags( $content );
if ( mb_strlen( $content ) <= $limit ) {
return $content;
}
$replacement = wp_html_excerpt( $content, $limit );
// Check if the description has space and trim the auto-generated string to a word boundary.
if ( strrpos( $replacement, ' ' ) ) {
$replacement = substr( $replacement, 0, strrpos( $replacement, ' ' ) );
}
}
}
return $replacement;
}