Site logo

[Support request] Assistance Needed With Custom Author Pages & Dealing With Author Slug Issues

Home Forums Support [Support request] Assistance Needed With Custom Author Pages & Dealing With Author Slug Issues

Home Forums Support Assistance Needed With Custom Author Pages & Dealing With Author Slug Issues

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #2503722
    Marty

    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!

    #2503804
    David
    Staff
    Customer Support

    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.

    #2503869
    Marty

    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!

    #2504071
    David
    Staff
    Customer Support

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

    #2504122
    Marty

    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.

    #2504134
    David
    Staff
    Customer Support

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

    #2504229
    Marty

    I’ve tried that and unfortunately I still ended up with the 404 page. šŸ™

    #2504691
    David
    Staff
    Customer Support

    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.

    #2505220
    Scott

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

    Edit Author Slug Settings

    #2505629
    David
    Staff
    Customer Support

    The issue here Scot is:

    https://generatepress.com/forums/topic/assistance-needed-with-custom-author-pages-dealing-with-author-slug-issues/#post-2503804

    We are trying to rewrite the query_vars so it retrieves the static page of the same name as the category.
    Problem is the default author_name is author.
    Whereas Marty has renamed his to authors

    If you have any ideas – it would be good to hear.

    #2505682
    Scott

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

    #2505800
    David
    Staff
    Customer Support

    Yeah, i believe the OP has set that option. It just won’t allow my code to work with it šŸ™‚

    #2506596
    Marty

    (deleted, to revise)

    #2506901
    Marty

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

    #2507006
    David
    Staff
    Customer Support

    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">
    
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.