WordPress only show content for logged in admin user

Sometimes one might only want to show some content for logged in admin users, or a specific admin user – for testing purposes etc.

you can use this code:

<?php 
$current_user = wp_get_current_user();
if($current_user->user_email == "email@address.co")
{
  function(); // this function will only happen when this one admin user is logged in.
?>
<p>This HTML will only show when the user is logged in</p>
<?php
}

For content to be shown when a user is logged in as an admin in general, this can be used:

<?php if ( is_user_logged_in() ) {
  echo "This will be shown if a user is logged into the admin section.";
} ?> 

comment Comments