title

Exclude pages from admin edit pages list

 

Exclude pages from admin edit pages list

10 Mai 2013, Posted by antoine in

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.

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;
}