Conditional Author Box

Get the latest from
Sniffle Valve

Sniffle Valve

Consider buying Sniffle Valve a coffee  

Book a one-on-one online training session

Note: To copy any code presented in these tutorials, hover over the code and select the Toggle RAW Code icon raw code icon

In this video, you will see how to create and display a custom author box based upon the nickname value for the author as noted in the author’s user profile in the WordPress admin Users area.

GeneratePress is the theme and the GeneratePress Premium add on is used to facilitate the GP Hooks functionality. GP Hooks also has the ability to optionally execute PHP, which is needed for this process.


Note: substitute “author-1-nickname”, etc., and “XXX” with your own values.

<?php  $author = get_the_author_meta('nickname'); if (is_single())

switch ($author) {
    case "author-1-nickname":
        echo do_shortcode('');
    case "author-2-nickname":
        echo do_shortcode('');
    case "author-3-nickname":
        echo do_shortcode('');

If you have only the one author, then you can use this code instead, substituting the “XXX” with your own value.

<?php if ( is_single() ) { ?>
    <?php echo do_shortcode(''); ?>
<?php } ?>


Leave a Comment

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