Site logo

Archived topic

Assistance Needed With Custom Author Pages & Dealing With Author Slug Issues

16 replies · Started by Marty on January 21, 2023

Viewing posts 1–15 of 17

Hi everyone, I have tried everything and searched extensively, but I simply can't figure this one out. My goals are the following:

  • Add an author box to posts, linking to the desired author page; (DONE, that works, based on the PHP in this GP support thread)
  • Direct the author slug to a custom page rather than the default author archive type page. In other words, I'd like to have a static, standard page I can use for my author content rather than the author field data normally displayed. With the result similar to this Domain/Authors/xx-author/ example.

However, I've run into obstacles I haven't been able to resolve:

  • I can create /authors/martym/ and it works, but only if I don't change the default WP slug /author/marty/.
  • Changing the default author slug to /authors/xxx gives a 404 on my custom author page; i.e., anything like /authors/xxx is a 404 and will not appear.
  • The author box will always reference the current WP author slug, not a custom URL, if I wanted to try that as a workaround.
  • I tried somehow adding & modifying author.PHP but couldn't get that to work as a standard page either.

I'd really appreciate your help as I have been struggling to figure this out. Thank you!

Hi there,

in this doc we show how to use static pages for category archives.
https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/

And we can change that code so it applies to author archives.

Try this:

add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['author_name'] ) ) {
        $pagename = $query_vars['author_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

Then you just need to create a static page that has the same name as the author.

Hi David and thanks a lot. That seems to work partially, at least on the author page end. :)

Unfortunately, I end up with two different "author list" base URLs: Wordpress (author box link, etc.) has /author/xxx/ while in reality, I have /authors/xxx/ for page structure.

If I change the slug base /author/ to /authors/ by the Edit Author Slug plugin in an attempt to be consistent I'm back at getting a 404 again.

Thank you!

How did you change the /author to /authors for the archive ?

Hi David. My apology if I wasn't clear when I mentioned it above, but it's the Edit Author Slug plugin I used as I don't currently know how to do so otherwise.

What happens if you try rebuilding the permalinks?
To do that, go to Settings > Peramlinks and click Save Changes

I've tried that and unfortunately I still ended up with the 404 page. :(

Any chance you can ask the Edit Author Slug plugin developer ?
As i am not sure how to accomplish the query vars change to use a static page if that plugin has rewritten the permalink.

I use this plugin. Did these setting options not work for you?

Edit Author Slug Settings

The Author Base can be changed to “authors” for the default “slug”. Further down that page (not shown) a custom display name can be entered for the user so the “page” would be accesses at /authors/customdisplayname/

So unless I’m not getting what we’re trying to achieve I think the simple way works.

Anyway, I’ll defer and follow. 😊

Yeah, i believe the OP has set that option. It just won't allow my code to work with it :)

(deleted, to revise)

@Scott @David, thank you both.

David, couldn't the GP author box code be modified as a workaround? The WP author bio link in the author box by default will be /author/. If I could change that to /xxxx/ (/authors/ for example) it would work, I believe.

This is the author URL PHP code portion from this thread:

<div class="author-links">
 
            <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="Read more">
                ...
            </a>
 
        </div>

I wasn't able to figure out how to modify this. Thank you again!

This line:

<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="Read more">

Try replacing with:


<?php
$author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
$new_author_url = str_replace( 'author', 'authors' , esc_url( $author_url) );
?>
<a href="<?php echo $new_author_url; ?>" title="Read more">
This archived topic is closed to new replies.