Title: wp_get_document_title
Published: December 9, 2015
Last modified: February 24, 2026

---

# wp_get_document_title(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#user-contributed-notes)

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

Returns document title for the current page.

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

 string Tag with the document title.

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

    ```php
    function wp_get_document_title() {

    	/**
    	 * Filters the document title before it is generated.
    	 *
    	 * Passing a non-empty value will short-circuit wp_get_document_title(),
    	 * returning that value instead.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param string $title The document title. Default empty string.
    	 */
    	$title = apply_filters( 'pre_get_document_title', '' );
    	if ( ! empty( $title ) ) {
    		return $title;
    	}

    	global $page, $paged;

    	$title = array(
    		'title' => '',
    	);

    	// If it's a 404 page, use a "Page not found" title.
    	if ( is_404() ) {
    		$title['title'] = __( 'Page not found' );

    		// If it's a search, use a dynamic search results title.
    	} elseif ( is_search() ) {
    		/* translators: %s: Search query. */
    		$title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );

    		// If on the front page, use the site title.
    	} elseif ( is_front_page() ) {
    		$title['title'] = get_bloginfo( 'name', 'display' );

    		// If on a post type archive, use the post type archive title.
    	} elseif ( is_post_type_archive() ) {
    		$title['title'] = post_type_archive_title( '', false );

    		// If on a taxonomy archive, use the term title.
    	} elseif ( is_tax() ) {
    		$title['title'] = single_term_title( '', false );

    		/*
    		* If we're on the blog page that is not the homepage
    		* or a single post of any post type, use the post title.
    		*/
    	} elseif ( is_home() || is_singular() ) {
    		$title['title'] = single_post_title( '', false );

    		// If on a category or tag archive, use the term title.
    	} elseif ( is_category() || is_tag() ) {
    		$title['title'] = single_term_title( '', false );

    		// If on an author archive, use the author's display name.
    	} elseif ( is_author() && get_queried_object() ) {
    		$author         = get_queried_object();
    		$title['title'] = $author->display_name;

    		// If it's a date archive, use the date as the title.
    	} elseif ( is_year() ) {
    		$title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );

    	} elseif ( is_month() ) {
    		$title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );

    	} elseif ( is_day() ) {
    		$title['title'] = get_the_date();
    	}

    	// Add a page number if necessary.
    	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    		/* translators: %s: Page number. */
    		$title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
    	}

    	// Append the description or site title to give context.
    	if ( is_front_page() ) {
    		$title['tagline'] = get_bloginfo( 'description', 'display' );
    	} else {
    		$title['site'] = get_bloginfo( 'name', 'display' );
    	}

    	/**
    	 * Filters the separator for the document title.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param string $sep Document title separator. Default '-'.
    	 */
    	$sep = apply_filters( 'document_title_separator', '-' );

    	/**
    	 * Filters the parts of the document title.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param array $title {
    	 *     The document title parts.
    	 *
    	 *     @type string $title   Title of the viewed page.
    	 *     @type string $page    Optional. Page number if paginated.
    	 *     @type string $tagline Optional. Site description when on home page.
    	 *     @type string $site    Optional. Site title when not on home page.
    	 * }
    	 */
    	$title = apply_filters( 'document_title_parts', $title );

    	$title = implode( " $sep ", array_filter( $title ) );

    	/**
    	 * Filters the document title.
    	 *
    	 * @since 5.8.0
    	 *
    	 * @param string $title Document title.
    	 */
    	$title = apply_filters( 'document_title', $title );

    	return $title;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/general-template.php#L1176)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/general-template.php#L1176-L1297)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#hooks)󠁿

 [apply_filters( ‘document_title’, string $title )](https://developer.wordpress.org/reference/hooks/document_title/)

Filters the document title.

 [apply_filters( ‘document_title_parts’, array $title )](https://developer.wordpress.org/reference/hooks/document_title_parts/)

Filters the parts of the document title.

 [apply_filters( ‘document_title_separator’, string $sep )](https://developer.wordpress.org/reference/hooks/document_title_separator/)

Filters the separator for the document title.

 [apply_filters( ‘pre_get_document_title’, string $title )](https://developer.wordpress.org/reference/hooks/pre_get_document_title/)

Filters the document title before it is generated.

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

| Uses | Description | 
| [get_search_query()](https://developer.wordpress.org/reference/functions/get_search_query/)`wp-includes/general-template.php` |

Retrieves the contents of the search WordPress query variable.

  | 
| [get_the_date()](https://developer.wordpress.org/reference/functions/get_the_date/)`wp-includes/general-template.php` |

Retrieves the date of the post.

  | 
| [post_type_archive_title()](https://developer.wordpress.org/reference/functions/post_type_archive_title/)`wp-includes/general-template.php` |

Displays or retrieves title for a post type archive.

  | 
| [single_term_title()](https://developer.wordpress.org/reference/functions/single_term_title/)`wp-includes/general-template.php` |

Displays or retrieves page title for taxonomy term archive.

  | 
| [single_post_title()](https://developer.wordpress.org/reference/functions/single_post_title/)`wp-includes/general-template.php` |

Displays or retrieves page title for post.

  | 
| [is_404()](https://developer.wordpress.org/reference/functions/is_404/)`wp-includes/query.php` |

Determines whether the query has resulted in a 404 (returns no results).

  | 
| [is_search()](https://developer.wordpress.org/reference/functions/is_search/)`wp-includes/query.php` |

Determines whether the query is for a search.

  | 
| [is_singular()](https://developer.wordpress.org/reference/functions/is_singular/)`wp-includes/query.php` |

Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).

  | 
| [is_year()](https://developer.wordpress.org/reference/functions/is_year/)`wp-includes/query.php` |

Determines whether the query is for an existing year archive.

  | 
| [is_front_page()](https://developer.wordpress.org/reference/functions/is_front_page/)`wp-includes/query.php` |

Determines whether the query is for the front page of the site.

  | 
| [is_tax()](https://developer.wordpress.org/reference/functions/is_tax/)`wp-includes/query.php` |

Determines whether the query is for an existing custom taxonomy archive page.

  | 
| [is_home()](https://developer.wordpress.org/reference/functions/is_home/)`wp-includes/query.php` |

Determines whether the query is for the blog homepage.

  | 
| [is_category()](https://developer.wordpress.org/reference/functions/is_category/)`wp-includes/query.php` |

Determines whether the query is for an existing category archive page.

  | 
| [is_tag()](https://developer.wordpress.org/reference/functions/is_tag/)`wp-includes/query.php` |

Determines whether the query is for an existing tag archive page.

  | 
| [is_author()](https://developer.wordpress.org/reference/functions/is_author/)`wp-includes/query.php` |

Determines whether the query is for an existing author archive page.

  | 
| [is_month()](https://developer.wordpress.org/reference/functions/is_month/)`wp-includes/query.php` |

Determines whether the query is for an existing month archive.

  | 
| [is_day()](https://developer.wordpress.org/reference/functions/is_day/)`wp-includes/query.php` |

Determines whether the query is for an existing day archive.

  | 
| [is_post_type_archive()](https://developer.wordpress.org/reference/functions/is_post_type_archive/)`wp-includes/query.php` |

Determines whether the query is for an existing post type archive page.

  | 
| [get_queried_object()](https://developer.wordpress.org/reference/functions/get_queried_object/)`wp-includes/query.php` |

Retrieves the currently queried object.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_x()](https://developer.wordpress.org/reference/functions/_x/)`wp-includes/l10n.php` |

Retrieves translated string with gettext context.

  | 
| [get_bloginfo()](https://developer.wordpress.org/reference/functions/get_bloginfo/)`wp-includes/general-template.php` |

Retrieves information about the current site.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 18 more](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#)

| Used by | Description | 
| [_wp_render_title_tag()](https://developer.wordpress.org/reference/functions/_wp_render_title_tag/)`wp-includes/general-template.php` |

Displays title tag with content.

  | 
| [_block_template_render_title_tag()](https://developer.wordpress.org/reference/functions/_block_template_render_title_tag/)`wp-includes/block-template.php` |

Displays title tag with content, regardless of whether theme has title-tag support.

  | 
| [get_wp_title_rss()](https://developer.wordpress.org/reference/functions/get_wp_title_rss/)`wp-includes/feed.php` |

Retrieves the blog title for the feed title.

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#comment-content-3966)
 2.    [Rami Yushuvaev](https://profiles.wordpress.org/ramiy/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_document_title/#comment-3966)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%23comment-3966)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%23comment-3966)
 4.  Basic Usage:
 5.      ```php
         <head>
         	<meta charset="<?php bloginfo( 'charset' ); ?>">
         	<meta name="viewport" content="width=device-width" />
         	<title><?php echo wp_get_document_title(); ?></title>
         	<?php wp_head(); ?>
         </head>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%3Freplytocom%3D3966%23feedback-editor-3966)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_get_document_title/?output_format=md#comment-content-1631)
 8.    [Khoi Pro](https://profiles.wordpress.org/khoipro/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_document_title/#comment-1631)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%23comment-1631)
     Vote results for this note: -5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%23comment-1631)
 10. To use: add to _header.php_
 11.  * Basic Usage:
      *     ```php
              	&lt;meta charset=&quot;"&gt; 	 	 	  
            ```
        
      * [Rami Yushuvaev](https://profiles.wordpress.org/ramiy/) [6 years ago](https://developer.wordpress.org/reference/functions/wp_get_document_title/#comment-3965)
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_document_title%2F%3Freplytocom%3D1631%23feedback-editor-1631)

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