has_excerpt() WordPress Function

The has_excerpt() function in WordPress allows developers to check if a post or page has an excerpt set. This can be useful for conditionally displaying content based on whether or not an excerpt exists.

has_excerpt( int|WP_Post $post ) #

Determines whether the post has a custom excerpt.


Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.


Top ↑

Parameters

$post

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.


Top ↑

Return

(bool) True if the post has a custom excerpt, false otherwise.


Top ↑

Source

File: wp-includes/post-template.php

function has_excerpt( $post = 0 ) {
	$post = get_post( $post );
	return ( ! empty( $post->post_excerpt ) );
}


Top ↑

Changelog

Changelog
VersionDescription
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.