Molongui Authorship makes it easy to assign one or more bylines to a post. Upon activation, you’ll be able to start assigning multiple bylines right away. In order for those bylines to appear on the frontend, you may need to make some small modifications to your theme.
Available Template Tags
WordPress offers template tags like the_author()
and the_author_posts_link()
to display byline information associated with each post. You might see those inside files like single.php
and author.php
.
Molongui Authorship has similar template tags for displaying multiple bylines. These are located in the template-tags.php
file. The most relevant are:
/**
* Outputs the authors display names, without links to their archive pages.
* This tag must be used within 'The Loop'.
* This function is the one to use as replacement for 'the_author()' template tag.
*
* @param int $pid Post id. Defaults to null.
* @param string $separator Delimiter that should appear between the authors.
* @param string $last_separator Delimiter that should appear between the last two authors.
* @param string $before String to be prepended before the author name(s). Defaults to an empty string.
* @param string $after String to be appended after the author name(s). Defaults to an empty string.
* @return void Displays the byline.
*/
function the_molongui_author( $pid = null, $separator = ', ', $last_separator = '', $before = '', $after = '' )
{
echo get_the_molongui_author( $pid, $separator, $last_separator, $before, $after );
}
/**
* Outputs the authors display names, with links to their archive pages.
* This tag must be used within 'The Loop'.
* This function is the one to use as replacement for 'the_author_posts_link()' template tag.
*
* @param int $pid Post id. Defaults to null.
* @param string $separator Delimiter that should appear between the authors.
* @param string $last_separator Delimiter that should appear between the last two authors.
* @param string $before String to be prepended before the author name(s). Defaults to an empty string.
* @param string $after String to be appended after the author name(s). Defaults to an empty string.
* @return void Displays the byline with linked names.
*/
function the_molongui_author_posts_link( $pid = null, $separator = ', ', $last_separator = '', $before = '', $after = '' )
{
echo get_the_molongui_author_posts_link( $pid, $separator, $last_separator, $before, $after );
}
Each of these template tags will present different aspects of the multiple bylines. For instance, the first will display the first and last name of each author without any links. The second will display the first and last name of author linking back to their author profile page. And so on.
Integrating Template Tags Into Your Theme
To integrate Molongui Authorship, you’ll want to replace existing author template tags in your theme with a simple conditional that uses the Molongui Authorship template tags if Molongui Authorship is available. The conditional prevents your site from breaking (e.g. white screen of death) if Molongui Authorship isn’t activated.
For example, here’s how you would update the_author_posts_link()
to instead use the_molongui_author_posts_links()
:
/**
* MOLONGUI AUTHORSHIP
* Using Molongui Authorship template tags.
*/
if ( function_exists( 'the_molongui_author_posts_link' ) )
{
the_molongui_author_posts_link();
}
else
{
the_author_posts_link();
}
However, the example above is a relatively simplistic way of presenting bylines. There’s a good chance your theme will need an adaptation of it. Below we explain how to integrate Molongui Authorship template tags in some of the most used themes:
Twenty Seventeen
Here’s how the change would look like for the WordPress’ Twenty Seventeen theme:
/**
* MOLONGUI AUTHORSHIP
* Added support for Molongui Authorship template tags.
*/
if ( ! function_exists( 'twentyseventeen_posted_on' ) )
{
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function twentyseventeen_posted_on()
{
if ( function_exists( 'get_the_molongui_author_posts_link' ) )
{
$byline = get_the_molongui_author_posts_link();
}
else
{
// Get the author name; wrap it in a link.
$byline = sprintf( _x( 'by %s', 'post author', 'twentyseventeen' ), '' . get_the_author() . '' );
}
// Finally, let's write all of this to the page.
echo '' . twentyseventeen_time_link() . ' ' . $byline . '';
}
}
GeneratePress
The GeneratePress theme provides the generate_post_author_output
filter. So we can make us of that helpful filter to hook our template tag function.
Try adding this piece of PHP code to your functions.php
file within your child theme:
/**
* MOLONGUI AUTHORSHIP
* Use theme's filter to customize byline with Molongui Authorship template tags.
* @see 'inc/structure/post-meta.php' file
*/
if ( function_exists( 'the_molongui_author_posts_link' ) )
{
add_filter( 'generate_post_author_output', function()
{
the_molongui_author_posts_link();
});
}