reubenross
Member
Posted 3 years ago #
Hi,
I'd like to display a link to an author's site, but only if one exists.
In other words... If there is an address entered in the Author's Website field (in the admin), then it'll have a link saying "Author's website" on my site. But if just 'http://' is entered in the Author's Website field, then nothing at all is displayed.
At the moment all I can do is display the link, but it is still displayed if there is no site.. and the link is just to 'http://'.
Can this be done?
Hello
This will display the link if they have set one and just their username if they have not. It is not exactly what you asked for, but it should be close:
<?php if (get_the_author_url()) { ?><a>" title="<?php the_author_url(); ?>"><?php the_author(); ?></a><?php } else { the_author(); } ?><?php } ?>
Hope it helps.
reubenross
Member
Posted 3 years ago #
Thanks alot for your reply. Would there be any way to modify this so that it shows nothing if they have not set one?
Untested:
<?php if (get_the_author_url()) { ?><a href="<?php the_author_url(); ?>" title="<?php the_author_url(); ?>"><?php the_author(); ?></a><?php } ?>
Hope it helps :)
reubenross
Member
Posted 3 years ago #
Ok, I did this:
<?php if (get_the_author_url()) { ?>Author's website: <a href="<?php the_author_url(); ?>" title="<?php the_author_url(); ?>"><?php the_author_url(); ?></a><?php } ?>
and for people who don't have a website, it still shows this:
Author's website: http://
So I guess it doesn't work? I want absolutely nothing for people with no website.
reubenross
Member
Posted 3 years ago #
Would anyone else know how to do this? I suppose a php if would work but I'm not that good when it comes to coding.
Help would be greatly appreciated.
andrewmalexander
Member
Posted 2 years ago #
This worked for us.
<?php $a=get_the_author_url();
if ($a!="http://") { ?>
"><?php the_author_url(); ?><br>
<?php }
if ($a=="http://")
;
?>