WP_REST_URL_Details_Controller::get_title()privateWP 5.9.0

Parses the title tag contents from the provided HTML.

{} It's a method of the class: WP_REST_URL_Details_Controller{}

No Hooks.

Return

String. The title tag contents on success. Empty string if not found.

Usage

// private - for code of main (parent) class only
$result = $this->get_title( $html );
$html(string) (required)
The HTML from the remote website at URL.

Changelog

Since 5.9.0 Introduced.

Code of WP_REST_URL_Details_Controller::get_title() WP 6.0

private function get_title( $html ) {
	$pattern = '#<title[^>]*>(.*?)<\s*/\s*title>#is';
	preg_match( $pattern, $html, $match_title );

	if ( empty( $match_title[1] ) || ! is_string( $match_title[1] ) ) {
		return '';
	}

	$title = trim( $match_title[1] );

	return $this->prepare_metadata_for_output( $title );
}