Archived topic
Replace link to Author page
24 replies · Started by Dave on February 9, 2023
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.
Hi Dave,
Can I see your site to check the structure?
Hi Ying,
Sure, what do you need from me in order to do that?
Oh you just need to link me to a page or post where I can see the author's byline :)
Oh sorry, here you go: https://www.irreverentgent.com/best-dr-squatch-soap-scents/
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' : ''
);
});
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.
You can add the PHP code to the functions.php of your child theme, or to a plugin like code snippet.
Nice. I’m going to try this too.
Hi Scott,
Let me know if it works :)
I added it to code snippet, but no luck, unfortunately!
Can you show me the exact code you are using? please wrap the code with the code tag so it keeps format :)
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' : ''
);
});
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 …
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.