Home / admin / Exclude pages from admin edit pages list
  • How to Exclude pages from admin edit pages list


    This is a great little snippet that will exclude pages based on the the ID from the admin pages list. Just add this snippet to the functions.php of your wordpress theme and update the array with the page ID’s you wish to hide. Please note this does not stop a post from being editable this snippet only hides the page from view.

    ( click code to copy )

    wordpress snippet : PHP

    add_action( 'pre_get_posts' ,'exclude_this_page' );
    function exclude_this_page( $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(23,28,30) ); // page id
    	return $query;

    ( WordPress codex functions, hooks, in this snippet. )

    query, get_post, get_posts, is_page, add_action, __, _n, is_admin, get_query_var,
  • This is fantastic, thanks for sharing it with us

    • No problem glad you like the wordpress snippets!

  • Der Applej├╝nger

    So great!!!
    Thank you so much. You saved my ass. ­čśÇ

  • Eric

    Is there a way to hide pages from specific users?

  • acs04

    Thanks for this tip. But, is it possible to exclude posts (or pages, custom post type) with ID less than a value (ie : if post ID < 1543 do not display in the admin view) ? I've a web site that has more than 4 000 000 hierarchical posts… and perhaps it could be useful (in the admin, WP makes a query on the order page… which is not indexed, and so, query is very very very slow)