Advertisement
RevelationTravis

WordPress Exclude Pages from Admin Area by Slug

Apr 15th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. function exclude_pages_from_admin_by_slug ($query) {
  2.     global $pagenow,$post_type;
  3.  
  4.     //set the array of to be excluded slugs
  5.     $excludeds = array(
  6.         'login',
  7.         'logout',
  8.         'lostpassword',
  9.         'register',
  10.         'resetpass'
  11.     );
  12.    
  13.     //get array of IDs from array of slugs
  14.     foreach ( $excludeds as $excluded ) {
  15.         $excluded_IDs[] = get_page_by_path( $excluded )->ID;
  16.     }
  17.  
  18.     if (!is_admin() && $pagenow=='edit.php' && $post_type =='page') {
  19.         //exclude those IDs from query
  20.         $query->query_vars['post__not_in'] = $excluded_IDs;
  21.     }
  22. }
  23. add_filter( 'parse_query', 'exclude_pages_from_admin_by_slug' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement