WordPress.org

Support

Support » How-To and Troubleshooting » A solution to the “http://” problem when using the_author_url() template tag.

A solution to the “http://” problem when using the_author_url() template tag.

  • 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:

    by
    <?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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

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

    This is built in functionality.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A solution to the “http://” problem when using the_author_url() template tag.’ is closed to new replies.