How to Restrict WordPress Front End “Edit” Links to Admins Only

Say you have a blog where you allow Authors & Editors on the site, but for whatever reason, you don’t want the Edit links that can be displayed on the front end with edit_post_link() to show up for them. Well, here’s how you’d do that.

Firstly, this isn’t an easy, global situation. You need to find all instances of the edit_post_link() function in your theme. Once you do, replace that call altogether with:


<?php global $user_level;
get_currentuserinfo();
if ($user_level == 10) { edit_post_link('Edit', '<p class="button edit">', '</p>'); } ?>

I use this on a site that I allow users to create new posts (via the Gravity Forms plugin), but I don’t want them to be able to access the backend at all, though I still want administrators to be able to easily access any post via those “Edit” links.

People are Talking, Talking 'bout People

Your Turn

You could be famous! If this post goes viral, imagine if you were first...

Your email address will not be published.