Web Dev Tuts

/ Stuffs About Website Development /

Menu
  • Home
  • Wp Plugins
  • How To
  • FAQ
    • GIT
    • JQuery
    • PHP
    • WooCommerce
    • WordPress
  • Contact Us
Menu
How to Hide Certain Pages from Editor (WP Dashboard)

How to Hide Certain Pages from Certain Users (WP Dashboard)

Posted on February 27, 2020March 1, 2020 by Edesa Cee
How to Hide Certain Pages from Editor (WP Dashboard)

There are instances wherein there is a need to hide some pages from certain users because we don’t want them to edit those pages.

Code snippet:

add_filter( 'pre_get_posts', 'removePageFromDashboard' );

function removePageFromDashboard($query) {
  $user = wp_get_current_user();
  if (is_admin() && in_array( 'editor', (array) $user->roles )) {
    $hide_pages = array(postid1, postid2);
    $query->set('post__not_in', $hide_pages);
    return $query;
  }

} //function
Category: Wordpress

Recent Posts

  • How to add wp_editor Dynamically
  • How to Hide Certain Pages from Certain Users (WP Dashboard)
  • How to Set Up Gmail SMTP
  • How to Set Up Virtual Host in Localhost & Xampp
  • How to Determine the Current WordPress Version Used
  • AngularJs
  • CSS
  • For Me Only
  • geo location api
  • GIT
  • GoDaddy
  • Hosting
  • How To
  • Javascript
  • JQuery
  • Magento
  • My Notes
  • PHP
  • Private
  • Sass
  • WooCommerce
  • Wordpress
  • Xampp
© 2023 Web Dev Tuts | Powered by Minimalist Blog WordPress Theme