W3cubDocs

/WordPress

WP_REST_URL_Details_Controller::get_title( string $html ): string

Parses the title tag contents from the provided HTML.

Parameters

$htmlstringrequired
The HTML from the remote website at URL.

Return

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

Source

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 );
}

Changelog

Version Description
5.9.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title