limit-wordpress-users only view own posts or pages

How to Limit WordPress Users to View and Edit Only Their Own Pages in the Admin Dashboard


How to Limit WordPress Users to View and Edit Only Their Own Pages in the Admin Dashboard

By default, WordPress allows users with page-editing privileges to see all pages created by every author in the admin dashboard. While restricting users to their own “Posts” is standard in some roles, doing the same for “Pages” requires a slight adjustment.

Whether you want a lightweight, code-based solution or a user-friendly plugin, here is a complete guide on how to configure WordPress so users can only see and manage their own pages.

limit-wordpress-users only view own posts or pages

Method 1: The Code-Based Solution (Lightweight & Recommended)

If you prefer to keep your website fast and avoid installing extra plugins, you can add a short code snippet to your theme’s functions.php file. This code intercepts backend queries and ensures non-administrator users only fetch content they created.

Step-by-Step Instructions:

  1. Log in to your WordPress Admin Dashboard.
  2. Navigate to Appearance > Theme File Editor (or use an FTP client to access your website files).
  3. Open the functions.php file of your active child theme.
  4. Append the following code snippet at the very bottom of the file:
/**
 * Restrict non-admin users to only view their own posts and pages in the dashboard.
 */
function restrict_admin_posts_and_pages_to_author($query) {
    // Target only the admin dashboard, the main repository query, and exclude administrators
    if (is_admin() && $query->is_main_query() && !current_user_can('manage_options')) {
        global $user_ID;
        
        // Apply restrictions to both 'post' and 'page' post types
        if ($query->get('post_type') == 'page' || $query->get('post_type') == 'post') {
            $query->set('author', $user_ID);
        }
    }
}
add_filter('pre_get_posts', restrict_admin_posts_and_pages_to_author);

How it works:

Once saved, any user who is not an administrator (e.g., Editors, Authors, Contributors) will only see their own authored content when clicking on “Posts” or “Pages” in the sidebar. The dashboard counts and item lists will automatically filter down to show only their work.


Method 2: The Plugin-Based Approach

If you prefer not to touch your theme’s code, or if you need granular control over specific user roles, you can achieve this easily using plugins.

Option A: Restrict User Content (Plug-and-Play)

This is a dedicated, lightweight plugin designed specifically for this exact problem.

  1. Go to Plugins > Add New.
  2. Search for Restrict User Content and click Install Now, then Activate.
  3. Result: Out of the box, it automatically restricts all non-admin roles so they can only see their own pages, posts, and uploaded media library files. No complex setup is required.

Option B: PublishPress Capabilities (Advanced Control)

If your users belong to high-level roles like “Editor”, they naturally have a capability called edit_others_pages. To revoke this and fine-tune their access, use a role manager plugin.

  1. Install and activate PublishPress Capabilities (or User Role Editor).
  2. Navigate to the newly added Capabilities menu in your sidebar.
  3. Select the specific User Role you want to restrict from the dropdown menu (e.g., Author).
  4. Locate the Pages permission matrix and configure it as follows:
    • Check (Allow): Edit (own) and Delete (own).
    • Uncheck (Deny): Edit Others, Delete Others, and Read Private.
  5. Click Save Changes.

Important Considerations & Requirements

When restricting page access, ensure your users still have the core permissions required to interact with the dashboard:

  • Required Capabilities: To even see the “Pages” menu option on their sidebar, the user’s role must possess the edit_pages capability.
  • Publishing Privileges: If you want them to be able to make pages live without an administrator’s approval, ensure publish_pages is active for their role.

To tailor this setup perfectly, what specific User Role (e.g., Author, Editor, or Custom Role) are your users assigned to? Let me know if you would like custom code or a precise permission matrix for that exact role.

Leave a Reply

Your email address will not be published. Required fields are marked *