Remove Author Slug & Replace With Username

I reviewed all related questions but none tackle this exactly so I’m posting the question in hopes the pro’s know how to handle this. I would like to change the author slug to remove the term /author/ completely like this;

currently example.com/author/username

Read More

want example.com/username

Moreover I’d like all posts related to an author to look like:

example.com/username/post-title

URl strucutres would resemble a.) either wpmu or b.) cpt without actually building either.

To add more context. I’m building a multi author blog where users have independent pages (author pages) that they can build, post, and share. All posts created by all authors will be included in the main loop (for now).

What’s my best case scenario and worse case scenario to achieve this?

Related posts

Leave a Reply

2 comments

  1. Just an idea: Use a MU installation and give the blog names the names of the authors (use Sub-directories). This way you should get much closer to what you want to achieve with on board stuff.

    This means that you’ll get your author names appended to the original domain and when you go there, you’ll see their blog pages = author posts.

    http://example.com - main domain
    http://example.com/hans
    

    This solution would avoid any sort of programming.

  2. One way to achieve this (and you have to be willing and able to hack WP) is the following:

    Part 1 – after an author posts a new post, you explicitly change the post GUID in the database. Here is a crude example/outline:

    $wpdb->update( 
            $table_name, 
            array(                          
                'guid' => (whatever url you want)
            ),
            array( 'id' =>  (post ID))
        );
    
    • $table_name is the table name for the specific author (e.g. ‘wp_12_posts’ for the 12th blog in your network).
    • ‘guid’ is where you enter the URL you want (example.com/username/post-title)
    • ‘id’ is the ID of the post created by the author

    This changes the GUID of the post in the DB – now comes the interesting part.

    Part 2 – add/edit index.php in your theme to handle your custom URLs. Here’s an outline:

    //construct the complete URL of the request 
        $guid = 'http://' . get_current_site()->domain . $_SERVER["REQUEST_URI"];
        //check if DB contains a row with this guid
        $post = $wpdb->get_row("SELECT * FROM " . $table_name . " WHERE guid = '" . $guid . "'");
    

    basically what you are doing here is looking for the GUID you explicitly set earlier before WP handles things the ‘usual’ way. If $post is not empty you can now take it from there.

    I am working on a complete post outlining this solution as we implemented it at Litefort for a service we are creating, check out developers.litefort.com for more.