Languages: English • Русский • 日本語 • (Add your language)
Retrieves a post given its title. If more than one post uses the same title, the post with the smallest ID will be returned.
Because this function uses the MySQL '=' comparison the $page_title will usually be matched as case insensitive with default collating.
<?php
get_page_by_title( $page_title, $output, $post_type );
?>
NULL when no posts found.
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.
<?php $page = get_page_by_title( 'About' ); wp_list_pages( 'exclude=' . $page->ID ); ?>
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');
get_page_by_title() is located in wp-includes/post.php
.
Page Tags: get_all_page_ids(), get_ancestors(), get_page(), get_page_link(), get_page_by_path(), get_page_by_title(), get_page_children(), get_page_hierarchy(), get_page_uri(), get_pages(), is_page(), page_uri_index(), wp_list_pages(), wp_page_menu()