WordPress.org

Ready to get started?Download WordPress

Forums

Posts By Author URL Modification (3 posts)

  1. ashes999
    Member
    Posted 7 years ago #

    I'm using the the_author_posts_link template tag. What I need to do is modify the actual URL; right now, it's using the username, eg. myblog.com/author/admin but I want myblog.com/admin, or even better, myblog.com/authornickname.

    Is there a plugin out there that can handle this? If not, can someone point me towards how I would write this? I've done a lot of PHP/MySQL before...

  2. Kafkaesqui

    Posted 7 years ago #

    Setting urls from site/author/authorname to site/authorname is not a PHP/MySQL thing. It's a .htaccess/mod_rewrite thing affecting your custom permalinks. The only way I imagine doing this is to add lines to your .htaccess, for example:

    RewriteRule ^(admin)/?$ /index.php?author_name=$1 [QSA,L]

    You would have to add one for each author you want to link to in this way. This is because pattern matching performed on custom urls take a non-declared top-level directory name (i.e. /admin) to be a Page, and nothing else. Modifying this action (as well as switching to nickname) would require changes to the WP core.

    Finally, to create a link on a post for this, you can combine a couple template tags:

    <a href="<?php bloginfo('home'); ?>/<?php the_author_login(); ?>"><?php the_author(); ?></a>

  3. ashes999
    Member
    Posted 7 years ago #

    Will this work beyond the first page, i.e. /author-name/2/ ?

Topic Closed

This topic has been closed to new replies.

About this Topic