WordPress.org

Forums

Adding Admin only nav links. (12 posts)

  1. YOTS
    Member
    Posted 8 years ago #

    I'm looking to add a link to my blog nav where only I, the Admin, can view the link when logged in, just like the Site Admin link that shows up when I'm logged in. I can't find anything online that mentions how to do this. Anyone knows?

  2. Andrew Ozz
    WordPress Dev
    Posted 8 years ago #

    You can use either:
    if ( current_user_can('edit_post') )
    or
    if ( $user_ID )
    There are some differences, so check them out first.

  3. YOTS
    Member
    Posted 8 years ago #

    Thanks but I'm not sure what the differences are or how to implement the code. Could you give me more details?

  4. Andrew Ozz
    WordPress Dev
    Posted 8 years ago #

    Try

    <?php if ( $user_ID ) { ?>
    <a>...</a>
    <php } ?>

    The link will show for any logged in user.

  5. YOTS
    Member
    Posted 8 years ago #

    Thanks. Now how do I make it so it's only visible to the admin instead of every logged in user?

  6. YOTS
    Member
    Posted 8 years ago #

    I'm getting the following error when I drop in that code:

    Parse error: syntax error, unexpected $end in /home/16094/domains/aisleone.net/html/wp-content/themes/default/sidebar.php on line 119

  7. Andrew Ozz
    WordPress Dev
    Posted 8 years ago #

    Then try this:

    if ( current_user_can('edit_posts') ) { ?>
    <a>...</a>
    <php }

    Look for the <?php ... ?> tags. You can paste this somewhere between them, or use them at the beginning and the end.

  8. YOTS
    Member
    Posted 8 years ago #

    I dunno dude it's not working. Im still getting that parse error. Thanks for the help though. I appreciate it.

  9. Andrew Ozz
    WordPress Dev
    Posted 8 years ago #

    Where about in sidebar.php are you trying to put this? You can paste it including <?php ... ?> just before the last </div>, line 67.

  10. YOTS
    Member
    Posted 8 years ago #

    I'm putting it in here:

    <?php wp_register(); ?>

    RIGHT HERE

    <?php wp_loginout(); ?>

  11. Andrew Ozz
    WordPress Dev
    Posted 8 years ago #

    It should work there... Did you surround it with <?php ... ?> like that:

    <?php if ( current_user_can('edit_posts') ) { ?>
    <a>...</a>
    <?php } ?>
  12. YOTS
    Member
    Posted 8 years ago #

    That worked man thanks! I probably typed it in wrong.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags