How To Display Content for Admin Only

To display specific content for an admin only in WordPress can be done easily, all you need to do is just write an if else statement with the same parameter.

In this example I will show you how to display simple stats from WordPress and display it on the front page.

Like our previous WordPress tricks, we need to tweak our theme files, for this trick we will have to play around with footer.php, as I want to display this information on the footer area.

How-To-Display-Content-for-Admin-Only-460x274

How To Display Content for Admin Only

1
2
3
4
5
<?php global $user_IDif$user_ID ) : ?>
<?php if( current_user_can('level_10') ) : ?>
<?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?>
<?php endif; ?>
<?php endif; ?>

 

In the display content for Admin only code above what we have done is checked if the current user is logged in and has a level_10, if the user has this level, the content will be displayed. if the user’s profile is below or they are logged out, then nothing will be displayed.

It’s easy right?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>