A solution to the "http://" problem when using the_author_url() template tag. (3 posts)

  1. phillyroll
    Posted 9 years ago #

    I spent the better part of the day looking for solutions to the following problem: I wanted to display the name of the post author, and if the author has no website, then I wanted to display the name not as a link; but if the author has a website, I wanted to display the author name as a link. I couldn't find anything that worked, and I looked around, so here is the solution I came up with:

    <?php $a=get_the_author_url();
    if ($a!="http://") { ?>
    <a href="<?php echo $a; ?>"><?php the_author(); ?></a>
    <?php }
    if ($a=="http://")
    echo get_the_author();

    The above should display "by Author Name" and if the author has a website, it should link. If he or she has no website, the name will appear without a link under it. The problem is that for some reason, when you try to modify the author URI in WordPress admin, you get "http://" even when you try to make it blank. That was causing problems when I tried to display an author who had no website.

    Sorry if this solution was already found and this is a waste of space, but I have been looking all day and couldn't find anything so I figured I would put it up.

  2. buzzdroid
    Posted 8 years ago #

    The plugin Author Web solves the "http://" problem and also the problem with the_author_link display usernames when users have deleted the "http://" from their profile url.

  3. Or you can just use this:
    <?php the_author_link(); ?>

    This is built in functionality.

    Edit: Ahh, reply to an exceedingly old post. Nevermind.

Topic Closed

This topic has been closed to new replies.

About this Topic