wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Exclude pages from admin edit pages list

wordpress snippet

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.

snippet :  PHPcopy
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;
source →

Did you like this post? If so please share it with your friends. Thanks!

  • http://www.facebook.com/smbm.tom Tom Lambie

    This is fantastic, thanks for sharing it with us

    • http://wpsnipp.com Kevin Chard

      No problem glad you like the wordpress snippets!

  • Der Applej├╝nger

    So great!!!
    Thank you so much. You saved my ass. :-D

  • 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)