Title: WP_REST_URL_Details_Controller::get_title
Published: February 3, 2022
Last modified: May 20, 2026

---

# WP_REST_URL_Details_Controller::get_title( string $html ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#wp--skip-link--target)

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

Parses the title tag contents from the provided HTML.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#parameters)󠁿

 `$html`stringrequired

The HTML from the remote website at URL.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php#L286)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php#L286-L297)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_URL_Details_Controller::prepare_metadata_for_output()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/prepare_metadata_for_output/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Prepares the metadata by: – stripping all HTML tags and tag entities.

  |

| Used by | Description | 
| [WP_REST_URL_Details_Controller::parse_url_details()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/parse_url_details/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Retrieves the contents of the title tag from the HTML response.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_title/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_url_details_controller%2Fget_title%2F)
before being able to contribute a note or feedback.