Site logo

[Resolved] Replace link to Author page

Home Forums Support [Resolved] Replace link to Author page

Home Forums Support Replace link to Author page

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #2527530
    Dave

    Hi There,

    Currently every post I publish has a byline, which links to the standard WordPress author page.

    For one author in particular (me), I’d like to change this so instead of linking here:

    https://www.irreverentgent.com/author/dave-bowden/

    The byline would link here:

    https://www.irreverentgent.com/about-dave-bowden/

    I could add a 301 redirect, but I’d prefer to do it without adding a redirect, if possible.

    #2527649
    Ying
    Staff
    Customer Support

    Hi Dave,

    Can I see your site to check the structure?

    #2527650
    Dave

    Hi Ying,

    Sure, what do you need from me in order to do that?

    #2527678
    Ying
    Staff
    Customer Support

    Oh you just need to link me to a page or post where I can see the author’s byline 🙂

    #2527688
    Dave
    #2527704
    Ying
    Staff
    Customer Support

    Try this PHP code, just need to replace the 1 in get_the_author_meta( 'ID' ) == 1 with your actual user ID.

    add_filter( 'generate_post_author_output', function() {
    	$byline = '<span class="byline">%1$s<span class="author%8$s" %5$s><a class="url fn n" href="%2$s" title="%3$s" rel="author"%6$s><span class="author-name"%7$s>%4$s</span></a></span></span> ';
    	$schema_type = generate_get_schema_type();
    	 if ( get_the_author_meta( 'ID' ) == 1 ) {
    
       printf(
    				$byline,
    				apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
    				'https://www.irreverentgent.com/about-dave-bowden/',
    				/* translators: 1: Author name */
    				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    				esc_html( get_the_author() ),
    				generate_get_microdata( 'post-author' ),
    				'microdata' === $schema_type ? ' itemprop="url"' : '',
    				'microdata' === $schema_type ? ' itemprop="name"' : '',
    				generate_is_using_hatom() ? ' vcard' : ''
    		  );
    }  else 
    	printf(
    				$byline,
    				apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				/* translators: 1: Author name */
    				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    				esc_html( get_the_author() ),
    				generate_get_microdata( 'post-author' ),
    				'microdata' === $schema_type ? ' itemprop="url"' : '',
    				'microdata' === $schema_type ? ' itemprop="name"' : '',
    				generate_is_using_hatom() ? ' vcard' : ''
    		   );
    });
    #2527734
    Dave

    Where do I add it? I tried adding it to both the functions.php and the content.php files but it didn’t seem to work.

    #2527761
    Ying
    Staff
    Customer Support

    You can add the PHP code to the functions.php of your child theme, or to a plugin like code snippet.

    #2527766
    Scott

    Nice. I’m going to try this too.

    #2527770
    Ying
    Staff
    Customer Support

    Hi Scott,

    Let me know if it works 🙂

    #2527791
    Dave

    I added it to code snippet, but no luck, unfortunately!

    #2527792
    Ying
    Staff
    Customer Support

    Can you show me the exact code you are using? please wrap the code with the code tag so it keeps format 🙂

    #2527793
    Dave

    I just copied what you gave me, and changed the ID number:

    add_filter( 'generate_post_author_output', function() {
    	$byline = '<span class="byline">%1$s<span class="author%8$s" %5$s><a class="url fn n" href="%2$s" title="%3$s" rel="author"%6$s><span class="author-name"%7$s>%4$s</span></a></span></span> ';
    	$schema_type = generate_get_schema_type();
    	 if ( get_the_author_meta( 'ID' ) == 2 ) {
    
       printf(
    				$byline,
    				apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
    				'https://www.irreverentgent.com/about-dave-bowden/',
    				/* translators: 1: Author name */
    				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    				esc_html( get_the_author() ),
    				generate_get_microdata( 'post-author' ),
    				'microdata' === $schema_type ? ' itemprop="url"' : '',
    				'microdata' === $schema_type ? ' itemprop="name"' : '',
    				generate_is_using_hatom() ? ' vcard' : ''
    		  );
    }  else 
    	printf(
    				$byline,
    				apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				/* translators: 1: Author name */
    				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    				esc_html( get_the_author() ),
    				generate_get_microdata( 'post-author' ),
    				'microdata' === $schema_type ? ' itemprop="url"' : '',
    				'microdata' === $schema_type ? ' itemprop="name"' : '',
    				generate_is_using_hatom() ? ' vcard' : ''
    		   );
    });
    #2527800
    Scott

    Does that author actually have content published? I was experimenting with an unrelated author page issue recently and nothing showed until content was actually published. Once published content from that author was there it worked.

    Just a guess …

    #2527830
    Ying
    Staff
    Customer Support

    Have you already used a custom function to change the author byline, if so, the new function might not work?

    And make sure the cache is cleared.

Viewing 15 posts - 1 through 15 (of 25 total)
  • You must be logged in to reply to this topic.