Возвращает короткую цитату записи. Чтобы вывести цитату на экран, используйте the_excerpt().
Использование
<?php get_the_excerpt( $post ); ?>
- $post число/объект WP_Post
- ID записи или объект WP_Post
По умолчанию: ничего
Возвращает
строку / Короткую цитату текущего поста.
Если у записи указан Отрывок — будет выведен он. Если цитата не задана – будет возвращен автоматический отрывок с начала текста.
Примеры
1. Вывод короткой цитаты в мета-тегах
<?php if ( is_single() ) { ?>
<meta name="description" content="<?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?>" />
<?php } ?> Исходный код get_the_excerpt()
Расположен в wp-includes/post-template.php строка 374
function get_the_excerpt( $post = null ) {
if ( is_bool( $post ) ) {
_deprecated_argument( __FUNCTION__, '2.3.0' );
}
$post = get_post( $post );
if ( empty( $post ) ) {
return '';
}
if ( post_password_required( $post ) ) {
return __( 'There is no excerpt because this is a protected post.' );
}
/**
* Filters the retrieved post excerpt.
*
* @since 1.2.0
* @since 4.5.0 Introduced the `$post` parameter.
*
* @param string $post_excerpt The post excerpt.
* @param WP_Post $post Post object.
*/
return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
}
показать весь код