Home › Forums › Support › Assistance Needed With Custom Author Pages & Dealing With Author Slug Issues
- This topic has 16 replies, 3 voices, and was last updated 3 years, 2 months ago by
David.
-
AuthorPosts
-
January 21, 2023 at 3:08 am #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/xxxgives a 404 on my custom author page; i.e., anything like/authors/xxxis 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!
January 21, 2023 at 4:33 am #2503804David
StaffCustomer SupportHi 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.
January 21, 2023 at 6:18 am #2503869Marty
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!
January 21, 2023 at 8:07 am #2504071David
StaffCustomer SupportHow did you change the
/authorto/authorsfor the archive ?January 21, 2023 at 9:07 am #2504122Marty
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.
January 21, 2023 at 9:19 am #2504134David
StaffCustomer SupportWhat happens if you try rebuilding the permalinks?
To do that, go to Settings > Peramlinks and click Save ChangesJanuary 21, 2023 at 11:41 am #2504229Marty
I’ve tried that and unfortunately I still ended up with the 404 page. š
January 22, 2023 at 6:25 am #2504691David
StaffCustomer SupportAny 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.January 22, 2023 at 4:54 pm #2505220Scott
I use this plugin. Did these setting options not work for you?
January 23, 2023 at 3:47 am #2505629David
StaffCustomer SupportThe issue here Scot is:
We are trying to rewrite the query_vars so it retrieves the static page of the same name as the category.
Problem is the defaultauthor_nameisauthor.
Whereas Marty has renamed his toauthorsIf you have any ideas – it would be good to hear.
January 23, 2023 at 4:34 am #2505682Scott
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. š
January 23, 2023 at 6:30 am #2505800David
StaffCustomer SupportYeah, i believe the OP has set that option. It just won’t allow my code to work with it š
January 23, 2023 at 6:42 pm #2506596Marty
(deleted, to revise)
January 24, 2023 at 3:44 am #2506901Marty
@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!
January 24, 2023 at 5:16 am #2507006David
StaffCustomer SupportThis 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"> -
AuthorPosts
- You must be logged in to reply to this topic.