X

Exclude Pages from Admin Pages List by ID

Snippets by IsItWP

You may have seen the admin pages list on your WordPress dashboard. Some of these pages are not useful for you or someone using your website with the admin access. This snippet will exclude pages based on the ID from the admin pages list. Please note this does not stop a page from being editable but only hides the page from view.

Instructions: Add the following snippet to the functions.php file of your WordPress theme.
Make sure to replace the array IDs in the code below with the IDs of your admin pages.

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(10,2,14) ); // array page ids
	return $query;
}

You may also enjoy removing date filter on post type admin pages.

Comments   Leave a Reply

  1. you save my time
    thank you

  2. This is superb. I’m wondering (and may soon experiment) with using this to hide specific categories by ID for post formats and post types. Cheers.

  3. I’d like to hide pages from a date range, some idea out there?

    1. What are you trying to accomplish with this method?

      1. Hi Kevin,
        I just migrated/converted some content and now I have a lot of pages, I would like to hide them all in Pages and Parent Page dropdown. Just to keep the panels cleaner. Because those pages are needed but they won’t change anymore.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!