How Can We Help?

Replacing the Default Author Link with Bylines

You are here:
< Back

Replacing The Default Author Link:

This plugin is easy to use with themes that use the WordPress function the_author_posts_link or get_the_author_posts_link to display the author. This is a WordPress filter that works very well. Unfortunately, every theme author has a different way of doing things and few authors use this pluggable function. If your theme does not use this functionality, you can create a child theme using a plugin like the ‘Child Theme Configurator’ (make sure that you copy all of your settings to the child theme) and replace the code used to generate the author link with one of the above functions. Read more about child themes here. If you are having difficulties, please let us know and we will be happy to help you.

You may also use our function:

gap_the_author_posts_link ( $link ) to display a list of authors using the separator of your choice.

examples using child themes:

Twenty-Seventeen generates the author link in the file inc/template-tags.php in the theme folder. and uses this code to generate the author link:

’ . get_the_author() . ‘

You can safely replace this code in your custom theme with the filtered WordPress function.

gap_the_author_posts_link( get_the_author() );

Generate Press:

PHP
				function multiple_author_output($output) { 
if ( function_exists( 'gap_the_author_posts_link' ) ) { 
     if ( gap_has_co_authors() ) return 'by ' . gap_the_author_posts_link(''); 
} 
return $output; 
} 
add_action ('generate_post_author_output', 'multiple_author_output');
			

Twenty Twenty Child Theme File

When creating a child them for the TwentyTwenty theme, the twentytwenty_get_post_meta function, as is sometimes the case, is not pluggable. You can copy the entire template inc/template-tags.php file to your child theme. WordPress will load the template-tags.php in the child theme instead. Change the code that outputs the author from


printf(
	/* translators: %s: Author name */
												'' . esc_html( get_the_author_meta( 'display_name' ) ) . ''
							);
						

to

PHP
				printf(
/* translators: %s: Author name */
__( 'By %s', 'twentytwenty' ), get_the_author_posts_link() 
);
			

Here is what it looks like with a semicolon as a separator:

 

Must Use Function (Varia child theme)

Varia child themes – since you already have a child theme, you should create a php file in your wp-content/mu-plugins folder containing the following code to override the parent theme function:

PHP
				<?php
/*
Plugin Name: Varia Custom
Description: Custom code for multiple authors using the Guest Author Name Plugin
Version:     1.0

License:     GPL2 etc
License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
	function varia_posted_by() {
		global $varia_icon;
			$link = sprintf(
			/* translators: 1: SVG icon. 2: post author, only visible to screen readers. 3: author link. */
			'<span class="byline">%1$s<span class="screen-reader-text">%2$s</span><span class="author vcard"><a class="url fn n" href="%3$s">%4$s</a></span></span>',
			varia_get_icon_svg( 'person', 16 ),
			__( 'Posted by', 'varia' ),
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_html( get_the_author() )
		);
		if ( !isset( $varia_icon ) && function_exists( 'varia_get_icon_svg' ) ) {
		 $varia_icon = varia_get_icon_svg( 'person', 16 );
		}

		$links = gap_the_author_posts_link($link, $varia_icon );
		printf ( $links);
	}	?>