I have this snippet built from a couple of sources, it works great and if the user is not an admin it hides the page with an id of 243 from being seen in the edit pages section....

add_action( 'pre_get_posts' ,'exclude_pages' );
function exclude_pages( $query ) {
    if( !is_admin() )
        return $query;

    global $pagenow;
    if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' ==     get_query_var('post_type') ) )
        $query->set( 'post__not_in', array(243) );
    return $query;

I would really like to modify this so that it can work with page title instead of id, can anyone point me in the right direction?

1 Answer 1


Get the page by its title, then use its ID:

add_action('pre_get_posts', 'exclude_pages');
function exclude_pages($query) {
    if(! is_admin()) return $query;

    global $pagenow;
    if ('edit.php' === $pagenow && (get_query_var('post_type') && 'page' === get_query_var('post_type'))) {
        // Get the page by its title, ...
        $page = get_page_by_title('TITLE_HERE');
        // then use its ID
        $query->set('post__not_in', array($page->ID));
    return $query;

References: get_page_by_title

  • 1
    Thanks, just managed to get something similar working but your solution seems cleaner Apr 16, 2013 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.