Home / admin / Exclude pages from admin pages list by ID
  • Exclude pages from admin pages list by ID

    exclude-pages-from-edit-list-by-id

    Adding this snippet to the functions.php of your wordpress theme will let you remove pages from the admin pages list. Just update the list of page IDs within the array.

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

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

    query, get_post, get_posts, is_page, add_action, __, _n, is_admin, get_query_var,
  • http://www.facebook.com/profile.php?id=100000812961482 Diana Katayama

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

    • http://wpsnipp.com Kevin Chard

      What are you trying to accomplish with this method?

      • http://www.facebook.com/profile.php?id=100000812961482 Diana Katayama

        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.

  • ArleyM

    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.

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks