Get a free trial // Grow your CSS skills // Land your dream job

Admin Panel Link Only For Admins

Last updated on:
<?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. Metin
    Permalink to comment#

    really handy piece of code.
    thanks Chris.

  2. Jim
    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’, ”, ”); ?>

      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. Ahmad Awais
    Permalink to comment#

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

  4. 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. madalin
    Permalink to comment#

    You insert that into your theme functions.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed