get_page_by_title( string $page_title, string $output = OBJECT, string|array $post_type = 'page' )

Retrieve a page given its title.

Description Description

Parameters Parameters


(string) (Required) Page title


(string) (Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively.

Default value: OBJECT


(string|array) (Optional) Post type or array of post types.

Default value: 'page'

Top ↑

Return Return

(WP_Post|array|null) WP_Post (or array) on success, or null on failure.

Top ↑

Source Source

File: wp-includes/post.php

function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
	global $wpdb;

	if ( is_array( $post_type ) ) {
		$post_type = esc_sql( $post_type );
		$post_type_in_string = "'" . implode( "','", $post_type ) . "'";
		$sql = $wpdb->prepare( "
			FROM $wpdb->posts
			WHERE post_title = %s
			AND post_type IN ($post_type_in_string)
		", $page_title );
	} else {
		$sql = $wpdb->prepare( "
			FROM $wpdb->posts
			WHERE post_title = %s
			AND post_type = %s
		", $page_title, $post_type );

	$page = $wpdb->get_var( $sql );

	if ( $page ) {
		return get_post( $page, $output );

Top ↑

Changelog Changelog

Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    How To Find WordPress Page ID By Title Then Replace the_content()

    In this example, we find the page id of “Sample Page” then replace the page’s the_content() with “Hello World!”

    function my_content($content) {
    	$page = get_page_by_title( 'Sample Page' );
    	if ( is_page($page->ID) )
    		$content = "Hello World!";
    	return $content;
    add_filter('the_content', 'my_content');
  2. Skip to note content
    Contributed by Codex

    Find Page ID to use with exclude in wp_list_pages

    This example will return the $page object for the page titled “About”. Then the $page->ID element is used to exclude the About page when listing pages.

    $page = get_page_by_title( 'About' );
    wp_list_pages( 'exclude=' . $page->ID );

You must log in before being able to contribute a note or feedback.