Help with get_the_author php code


I am pretty much php illiterate so please bear with me! I want to add a second author to the following code snippet, but I have no idea how:

<?php if ( get_the_author() == 'DeAnn Elliott') { echo("DeAnn's Blog: "); } ?><?php the_title(); ?>

I want to keep DeAnn as an author and add Sail Blind (with an echo of "SailBlind’s Blog: ") as an author. Thank you in advance for your help!


This really is a Wordpress question, but seeing as it is simple, I’ll answer it anyway.

The control structure you are after is a switch/case block, as follows:

<?php switch (get_the_author()) { case "DeAnn Elliott": echo "DeAnn's Blog: "; break; case "Sail Blind": echo "SailBling's Blog: "; break; } echo get_the_title(); ?>


Thank you! I apologize for not posting in the correct place, but I’ll know for next time. I was able to get the following code to work as well. Is there a preference between the case break and if else formats?

<?php if ( get_the_author() == 'DeAnn Elliott') { echo("DeAnn's Blog: "); } else { if ( get_the_author() == 'Sail Blind') echo("SailBlind's Blog: "); } ?><?php the_title(); ?>

In purpose, they’re the same. In practice, if/else tends to get very messy as you get more and more of them. switch/case allows you to get everything neatly together in cases.

(Also, switch is faster as you’re only evaluating get_the_author once)

Sponsor our Newsletter | Privacy Policy | Terms of Service