Support » Fixing WordPress » Problem with "the_author_meta('user_login')" an Usernames with whitespace

  • Resolved daveleeone


    Hi, I’ve a Problem with an extended autor-link and usernames with whitespace E.G.

    <a href="<?php bloginfo('url'); ?>/author/<?php the_author_meta('user_login'); ?>"><?php the_author_meta('first_name'); ?> </a>

    When I have a User whith the username “user name” then i get the link name/ but the correct link would be
    When I use the traditonal Author link <?php the_author_link(); ?> then I get the correct result.

    Does anyone know a solution to my problem?

    I use WordPress 3.2

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hello Dave,

    I am not exactly sure as to why the_author_meta does not convert white spaces properly and the_author_kink does, but you could take a look inside the functions to see how the data is handled.
    For a workaround, you could use:

    <a href="<?php the_author_link(); ?>"><?php the_author(); ?> </a>

    The function the_author will return the authors’s screen name, which, IMHO, is more flexible since it enables your authors to chose how they want their names displayed.

    Let me know if this helps!

    I can not use <php the_author_link ();?> because it prints the entire link with title

    I’ve used <php the_author_link ();?>but I get the URL of the Users website


    Moderator keesiemeijer



    Have you tried it with the other code example in the the_author_link page:

    <a href="<?php bloginfo('url'); ?>/author/<?php the_author_nickname(); ?>"><?php the_author_posts(); ?></a>

    or with get_author_posts_url()

    yes I have. with nickname I get the name of the user e.g. “Firstname Lastname” and not of the link

    Moderator keesiemeijer



    To get the correct url use something like this (in the loop):

    $author =  get_the_author_meta( 'ID');
    $url = get_author_posts_url( $author);

    @keesiemeijer: I tried the code you just posted, but without storing the info to variables, like so:

    get_author_posts_url(the_author_meta('ID') );

    Assuming the author’s ID in question is 1, it seems that the get_author_posts_url function outputs:

    instead of the proper author archive url, which would be:

    @dave: Sorry about that: I misunderstood what you were trying to accomplish. You could use the_author_posts_link instead, whcich would work fine, but you should know that the function is deprectated. However, it will do exactly what you are looking for: display the author’s screen name as a link to his/her archive posts.

    Moderator keesiemeijer



    echo get_author_posts_url(the_author_meta('ID') );

    doesn’t work for me.

    echo get_author_posts_url(get_the_author_meta( 'ID') );

    does work on my testserver. it echo’s

    thanks @keesiemeijer and @marventus
    it works perfectly with:
    <a href="<?php $author = get_the_author_meta( 'ID'); $url = get_author_posts_url( $author); echo $url;?>"><?php the_author_meta('first_name'); ?></a>

    @keesiemeijer: That makes sense, because I was trying to retrieve the ID (not to echo it), so I should have used get_author_post_meta instead of author_post_meta as you did in your example, 😉

    @dave: Glad you made it work. I’ll try to be more helpful next time, 🙂

    Hi Dave,

    Since you were able to figure this out, could you please mark this topic as resolved?


Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Problem with "the_author_meta('user_login')" an Usernames with whitespace’ is closed to new replies.