WP_REST_URL_Details_Controller::get_title
Parses the title tag contents from the provided HTML.
Method of the class: WP_REST_URL_Details_Controller{}
No Hooks.
Returns
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. |
WP_REST_URL_Details_Controller::get_title() WP REST URL Details Controller::get title code WP 7.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 );
}