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

<?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?

One thought on “How To Display Content for Admin Only

Leave a Reply

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