[resolved] Problem with "the_author_meta('user_login')" an Usernames with whitespace (11 posts)

  1. daveleeone
    Posted 4 years ago #

    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 www.mysite.com/author/user name/ but the correct link would be www.mysite.com/author/user-name/
    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

  2. Marventus
    Posted 4 years ago #

    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!

  3. daveleeone
    Posted 4 years ago #

    I can not use <php the_author_link ();?> because it prints the entire link with title http://codex.wordpress.org/Function_Reference/the_author_link#Example

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


  4. keesiemeijer
    Posted 4 years ago #

    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()

  5. daveleeone
    Posted 4 years ago #

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

  6. keesiemeijer
    Posted 4 years ago #

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

    $author =  get_the_author_meta( 'ID');
    $url = get_author_posts_url( $author);
  7. Marventus
    Posted 4 years ago #

    @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.

  8. keesiemeijer
    Posted 4 years ago #

    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 http://test.dev/author/keesie-meijer/

  9. daveleeone
    Posted 4 years ago #

    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>

  10. Marventus
    Posted 4 years ago #

    @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, :-)

  11. Marventus
    Posted 4 years ago #

    Hi Dave,

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


Topic Closed

This topic has been closed to new replies.

About this Topic