For a couple of days now, I’ve being wondering how to display something only for the admin to see, when the admin is logged in. This could come in handy to display links to the WP admin panel or stats page.
So I did a bit of research and I found exactly what I was looking for:
<?php global $user_ID; if( $user_ID ) : ?>
<?php if( current_user_can('level_10') ) : ?>
Stats
<?php else : ?>
<?php endif; ?>
<?php endif; ?>
The code above will display “Stats” with a link to a stats page, but only for the admin, when the admin is logged on.
You can modify the code above to display links only for certain types of users, such as Contributors, Authors, Editors, etc, by changing the “level_10“. Read more about WordPress Roles and Capabilities here.
This is just a quick little tutorial I wanted to share with you guys! Enjoy. Oh and if you know of any other ways to use this tutorial, please share!