Site logo

Archived topic

Pls help modify author

25 replies · Started by crosby87 on March 10, 2022

Viewing posts 1–15 of 26

Hi there,

Q1. I would like to have 2 questions regarding authors:
When you click on my name as author under a blog post it automatically redirects to a custom about page. This was set up using a code that you provided earlier. I would like to remain this as is.

I now however have new authors on my blog, and if you click on their names it also redirects to the About page. How can I avoid this? I only want my name to redirect to the about page, but not the other authors. Could you please help with this?

Q2. For some blog posts (where I am not the author), I would like to include a second author like this: Reviewed by: Author 2
So for those posts where I am not the author, I want to include myself as the person who reviewed it. Please see an example here: https://www.bankrate.com/investing/best-investments/ (see original author + review by author).

Could you please help with this?

Thank you in advance!

Hi there,

Q1: Can you provide the snippet you are using for this?

Q2: Please new topic for this so we can handle one question per topic.

Thanks!

Hi Leo,

Thanks for the quick answer.

Q1. See the code:

add_filter( 'author_link', 'my_author_link' );
 
function my_author_link() {
	return home_url( '/rolam' );
}

Q2. Ok, I'll submit a new one.

Try editing the snippet to this:

add_filter( 'author_link', 'my_author_link' );
 
function my_author_link() {
    if ( is_author( 'YOUR_NAME' ) ) {
	return home_url( '/rolam' );
    }
}

Hi Leo,

Thanks, I tried but it is not working. When I click on the name of the author it reloads the same page (looks like it redirects to the respective blog post I am at).

See code and link in private.

Hi Leo,

I just tried. I even took the accents (á and é) off my name and ran the code with space, dash (-) and underscore (_), but still doesn't work.

Hi there,

You can try user id which can be found in the user editor URL, in the below case, the user id is 2:
https://www.screencast.com/t/42hfBASreQ

And the PHP would be:

add_filter( 'author_link', 'my_author_link' );
 
function my_author_link() {
    if ( is_author( '2' ) ) {
	return home_url( '/rolam' );
    }
}

My link is a bit different, could you pls share which is my used ID?
See link in private.

Hi,

I used the code suggested by Ying using my ID, but it still does not work.

Try this GP filter instead:

add_filter( 'generate_post_author_output', function( $output ) {   
	
    $author_name = get_the_author_meta( 'display_name' );
    $custum_author_link = home_url( '/rolam' );
	
     if ( 2  === get_the_author_meta( 'ID' ) ) {
         return '<a href='.$custum_author_link.'>'.$author_name.'</a>';
    } 
	return $output ;
});
 

Just replace the 2 with your author ID.

Still does not work

Sorry, I cached my website and now it seems to partially work.
Does not seem to work on blog posts where I have a custom Header Element.

See details in private.

If the user link is in header element, try this:

add_filter( 'generate_page_hero_post_author', 'my_hero_author');

function my_hero_author($author) {
		
            global $post;
	    $author_id = $post->post_author;
	
        if ( '2'  === $author_id) {	
			$author = sprintf(
				'<span class="author vvcard" 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(home_url( '/rolam') ),
				/* translators: author name */
				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 ) )
			);
	return $author;
		}
	return $author;
}
This archived topic is closed to new replies.