Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WP_REST_URL_Details_Controller::get_title() WordPress Method

The WP_REST_URL_Details_Controller::get_title() method is used to retrieve the title of a given URL. This is useful for displaying the title of a URL in a list of results, for example.

WP_REST_URL_Details_Controller::get_title( string $html ) #

Parses the title tag contents from the provided HTML.


Parameters

$html

(string)(Required)The HTML from the remote website at URL.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php

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


Top ↑

Changelog

Changelog
VersionDescription
5.9.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.