WP_Posts_List_Table::get_no_title_excerpt( WP_Post $post ): string

Gets a trimmed excerpt to display in place of a missing post title.

Description

Only returns text in the Compact list view for posts that have no title, do not require a password, and that the current user is allowed to read.

Parameters

$postWP_Postrequired
The current WP_Post object.

Return

string The escaped, trimmed excerpt, or an empty string.

Source

protected function get_no_title_excerpt( $post ) {
	global $mode;

	if ( 'excerpt' === $mode
		|| '' !== get_the_title( $post )
		|| post_password_required( $post )
		|| ! current_user_can( 'read_post', $post->ID )
	) {
		return '';
	}

	$excerpt = get_the_excerpt( $post );

	if ( '' === $excerpt || ! is_string( $excerpt ) ) {
		return '';
	}

	return esc_html( wp_trim_words( $excerpt, 15 ) );
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.