Not every page is for public eyes: internal SOPs, server notes, draft policies. WordPress can lock content so only administrators see it, and the right method depends on whether you’re hiding a whole page, a whole category, or just one secret line inside an otherwise public post.
current_user_can('manage_options') shortcode. Match the method to the scope: whole page, whole category, or inline snippet.WordPress’s permission model already knows who’s an administrator; these three methods just decide where that check applies. Here they are, smallest scope of tooling first.
Built-in toggle. Hides a post from everyone below Editor. Fast, plugin-free — but visible to Editors too, not admin-only.
Members, or User Role Editor Pro: a content-permissions box. Role-precise (admins only, exclude Editors), whole categories at once.
Wrap one line in a current_user_can check. Post stays public; the secret shows only to admins.
Table of Contents
Method 1: the Private visibility toggle (no plugin)
The fastest way to hide a single document, built into WordPress:
- Open the post or page.
- In the sidebar under Status & Visibility, click the link next to Visibility (it says “Public”).
- Choose Private and confirm, then Update.
A Private post is visible only to Administrator and Editor roles; for everyone else it vanishes from search, feeds, and navigation. That’s the catch worth knowing: Private includes Editors, not admins only. If you must exclude Editors too, use Method 2.
“Private” hides a post from everyone below Editor — quick and plugin-free, but it’s not admin-only.
Method 2: a roles plugin (granular and bulk)
When you need role-precise control (admins only, excluding Editors) or you’re restricting many documents, install Members from the plugin repository. It adds a Content Permissions box to the editor:
- Open the document and scroll to the Content Permissions box.
- Check the role(s) allowed to view it, e.g. Administrator only.
- Optionally set a custom “access denied” message for anyone who hits the direct URL.
Reach for a plugin once “hide this” becomes “hide this whole class of documents from these specific roles”, a policy you don’t want to re-apply post by post.
Method 3: a shortcode for part of a public post
Sometimes the page is public but one line isn’t: a license key, an internal phone number. Wrap just that part in a capability-checked shortcode. Add the shortcode once (a code-snippets plugin, a site-specific plugin, or functions.php; it’s a textbook snippet-over-a-plugin case):
// [admin_only]…[/admin_only] — shows the wrapped content only to users who can manage the site.
add_shortcode( 'admin_only', function ( $atts, $content = '' ) {
return current_user_can( 'manage_options' ) ? do_shortcode( $content ) : '';
} );
Code language: PHP (php)
Then in the editor, sandwich the private text:
[admin_only]
Server key: (visible to admins only)
[/admin_only]Code language: CSS (css)
manage_options is the capability only administrators have by default, so the wrapped block renders for them and disappears for everyone else, while the rest of the post stays public.
Public post, private line: a capability-checked shortcode hides one secret without hiding the whole page.
Which method to use
Match the method to the scope of what you’re hiding:
- One page, quickly → Private visibility.
- A whole category of documents, or role-precise rules → a roles plugin (Members / User Role Editor Pro).
- A secret inside an otherwise public post → the
admin_onlyshortcode.
A note on expectations: these control display and access to rendered content, which is what you want for internal docs and secrets. They are not a substitute for real secrets management. Genuine credentials belong in a password manager or vault, not in a post, even a Private one.
The short version
To restrict WordPress content to admins, pick by scope. A whole page: set Visibility → Private (built in; visible to Editors too, so not strictly admin-only). Many documents or role-exact rules: a roles plugin (Members, or the paid User Role Editor Pro) and its content-permissions box. One secret line in a public post: an admin_only shortcode gated on current_user_can('manage_options'). And remember these gate content display, not secrets; real credentials belong in a vault, not a post.
Frequently Asked Questions
What does a visitor see if they open a Private post’s URL?
A “not found” page. WordPress answers a Private post with a 404 for anyone who isn’t logged in with a role allowed to read it, so the post doesn’t even reveal that it exists. Logged-in Administrators and Editors see it normally, with “Private:” in front of the title.
Can other editors see the text inside the admin_only shortcode?
Yes, if they can edit that post. The shortcode only controls what the published page renders. Anyone who opens the post in the editor sees the raw text between the tags, and earlier revisions keep copies of it too. Use the shortcode to hide a line from readers, not from people who can edit the post, and keep real credentials out of the post entirely.
What’s the difference between Members and User Role Editor?
Members manages roles and capabilities and, in its free version, adds a per-post Content Permissions box. The free User Role Editor only edits what each role can do; restricting who can view a post or page is a feature of its paid Pro version. For admin-only documents at no cost, Members is the one that covers it.