Admin Panel Link Only For Admins

<?php if (current_user_can("manage_options")) : ?>
       <a href="<?php echo bloginfo("siteurl") ?>/wp-admin/">Admin</a>
<?php endif; ?>

If a user is logged in and they are an Admin of the site (not just an subscriber or author), then display a link to get them to the WordPress Admin area. Otherwise, display nothing.

More specific than the regular log in / log out function, which will show for everyone:

<?php wp_loginout(); ?>


  1. User Avatar
    Permalink to comment#

    really handy piece of code.
    thanks Chris.

  2. User Avatar
    Permalink to comment#

    I think the following (within the loop) does the same thing and lets you go directly to the post or page you want to edit:

    <?php edit_post_link(‘Edit’, ”, ”); ?>

    • User Avatar
      Permalink to comment#

      Really handy! So, why not combine both scripts and have “Login” and “Edit” for Admins only?

      For example, inside the loop:

      // Begin WordPress loop
      if (have_posts()) : while (have_posts()) : the_post();
      // Admin only code
      <?php if (current_user_can("manage_options")) : ?>
      <a href="<?php echo bloginfo("siteurl") ?>/wp-admin/">Admin</a>
      <?php  edit_post_link(‘Edit’, ”, ”);  ?>
      <?php endif; ?>
      // code here, get contents
      // End WordPress loop
      <?php endwhile; else: ?>
      Sorry, no pages matched your criteria.
      <?php endif; get_footer(); ?>
  3. User Avatar
    Ahmad Awais
    Permalink to comment#

    Really a handy code but some more descriptions would have really made me appreciate you more

  4. User Avatar
    Alaga Michael
    Permalink to comment#

    i get the code but not that good with php so want to know where exactly do i insert the code, header, footer or the body. though i guess header since it deals with login/logout. and what specific purpose those this serve on a site

  5. User Avatar
    Permalink to comment#

    You insert that into your theme functions.

  6. User Avatar
    Permalink to comment#

    You better do not insert this in your theme functions.
    But do insert this code in any of the theme Templates:
    single.php, page.php, archive.php.

    It makes no sense to put it in functions.php since it is not logic function, rather representational function that needs to popup somewhere.

    You could, though, theoretically put it in functions.php, via filter function that defines when to present Admin link on any of the templates mentioned above :)

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.