- This topic has 25 replies, 3 voices, and was last updated 1 year, 10 months ago by
Tom.
-
AuthorPosts
-
February 17, 2020 at 8:48 am #1168212
Tom
Lead DeveloperLead DeveloperYou could try this instead:
add_filter( 'generate_page_hero_post_author', function() { global $post; $author_id = $post->post_author; $url = get_author_posts_url( $author_id ); if ( 1 === $author_id ) { $url = 'YOUR CUSTOM URL'; } if ( 2 === $author_id ) { $url = 'YOUR CUSTOM URL'; } return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( $url ), esc_attr( sprintf( __( 'View all posts by %s', 'gp-premium' ), get_the_author_meta( 'display_name', $author_id ) ) ), esc_html( get_the_author_meta( 'display_name', $author_id ) ) ); } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 18, 2020 at 6:23 pm #1169784Dana
Hey Tom. Sadly non of these options are working 100%.
Option 1 below does work if I use the search results page and click on the author but does not work from my post pages.
add_filter( 'author_link', function( $link, $author_id ) { if ( 1 === $author_id ) { return 'CUSTOM URL'; } if ( 2 === $author_id ) { return 'CUSTOM URL'; } return $link; }, 10, 2 );
Option 2 below is the same as option 1 functionality; works from search results page but not post pages.
add_action( 'wp', function() { add_filter( 'author_link', function( $link, $author_id ) { if ( 1 === $author_id ) { return 'CUSTOM URL'; } if ( 2 === $author_id ) { return 'CUSTOM URL'; } return $link; }, 10, 2 ); }, 50 );
Option 3 below doesn’t work from search results page or my post pages.
add_filter( 'generate_page_hero_post_author', function() { global $post; $author_id = $post->post_author; $url = get_author_posts_url( $author_id ); if ( 1 == $author_id ) { $url = 'CUSTOM URL'; } if ( 2 == $author_id ) { $url = 'CUSTOM URL'; } return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( $url ), esc_attr( sprintf( __( 'View all posts by %s', 'gp-premium' ), get_the_author_meta( 'display_name', $author_id ) ) ), esc_html( get_the_author_meta( 'display_name', $author_id ) ) ); } );
Options 1 & 2 are close but there still seems to be an issue with the Elements Post Hero Header I’m using with the
{{author}}
template tag as it still points to //mywebsite.com/author/author-name from my posts pages. From the search results page, hovering/clicking on the author name points to //mywebsite.com/custom-author-page.February 19, 2020 at 8:16 am #1170564Tom
Lead DeveloperLead DeveloperYou need to have the first function and the last function.
The first function will do it for your archives, while the last function will do it for the page heroes.
The first function should do it everywhere, but if it’s not working for page heroes, that last function is necessary.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 19, 2020 at 7:54 pm #1171048Dana
I get it now Tom. Thanks. I work on my site in the evenings and the brain is not firing on on cylinders after working all day.
The first function works for archives no problem.
However the third function was still returning the wrong URL. I tested the function by replacing the third parameter (author name) with the URL parameter and it printed out //mywebsite.com/author/author-name/ where the author name would normally show on the hero page and was still //mywebsite.com/author/author-name if I hovered over the the full url. This helped me troubleshoot if the function was actually working.
So I changed the PHP operator from ‘===’ (identical) to ‘==’ (equal) and it worked giving me //mywebsite.com/custom-author-page when I hovered and clicked the author name.
Thanks for your time and patience on this one while I brush up on my PHP chops.
February 20, 2020 at 9:57 am #1171825Tom
Lead DeveloperLead DeveloperAwesome, glad you got it working! 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 6, 2021 at 10:39 pm #1768348Victor
Hey Tom,
Does this still work? I tried it but it doesn’t seem to be working like it worked for the archive pages. I created a custom page at domain.com/authorname but when I go to domain.com/author/authorname, it is a different page.
May 7, 2021 at 3:04 am #1768628David
StaffCustomer SupportHi there,
that code simply replaces the Link in the archives so it will point to the ‘url’ added to the filter. It doesn’t redirect or replace the default author archive.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 7, 2021 at 10:27 am #1769403Victor
So do you think a 301 redirect is the best way to replace default author archives with the custom page I have created?
Thanks!
May 8, 2021 at 4:18 am #1770066David
StaffCustomer SupportThats an option. Or there is this method:
https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 8, 2021 at 7:27 am #1770444Victor
David sir,
Can you give me the code for this?
So normal archives are located at domain.com/authors/johndoe. I want this to be replaced by domain.com/john-doe. I am specifying this so that you can change the code appropriately in the case of author archives similar to category ones. There is no dash in the normal author archives url because it renders it based on the username of the author.
Thanks in advance.
May 9, 2021 at 9:48 am #1771512Tom
Lead DeveloperLead DeveloperHi there,
Is
john-doe
a static page? Or are you just trying to remove theauthor
part of the URL?If it’s a static page, setting up 301 redirects is the way to go. Not sure there’s a magic function for this.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.