Customizing the Multiple Authors Display in Your Theme

The Multiple Authors add-on allows you to show author details in your plugin or theme.

You can use the action “pp_multiple_authors_show_author_box” to display the author box programmatically:

<?php do_action( 'pp_multiple_authors_show_author_box' ); ?>

Customizing the author box

By default, the author box is only displayed in the Post or Page post types. You can add support for more post types using the filter:

<?php
add_filter( 'pp_multiple_authors_post_types', 'my_custom_post_type_filter' );

function my_custom_post_type_filter( $post_types ) {
    $post_types['my_custom_postype'] = esc_html__( 'MY Custom Post Type' );

    return $post_types;
}
?>

Change when the post type is visible

By default, the author box only works on the following conditions:

  • Is not the homepage
  • Is not a category page
  • Is a single post or page
  • Is a valid post type

You can change the result of the conditions test using the following filter:

<?php
add_filter( 'pp_multiple_authors_filter_should_display_author_box', 'my_filter_should_display' );

function my_filter_should_display( $display ) {
    if ( $my_conditions... ) {
        $display = false;
    }

    return $display;
}
?>

Custom markup

You can customize the look or markup of your author box using the following filter:

<?php
add_filter( 'pp_multiple_authors_filter_author_box_markup', 'my_custom_markup', 10, 3 );

function my_custom_markup( $html, $authors_iterator, $target ) {
    // Uncomment the following line and change it to enqueue your custom CSS file, if needed.
    // wp_enqueue_style( 'multipleauthors', get_stylesheet_uri( '/multipleauthors.css' ), false, PP_MULTIPLE_AUTHORS_VERSION, 'all' );

    // Load a legacy library
    if ( ! function_exists( 'multiple_authors' ) ) {
        require_once PP_MULTIPLE_AUTHORS_PATH_BASE . '/template-tags.php';
    }

    $css_class = '';
    if ( ! empty( $target ) ) {
	$css_class = 'pp-multiple-authors-target-' . str_replace( '_', '-', $target );
    }

    // You can ignore the given HTML and create your own
    $html = '<ul>';

    $authors_iterator->reset();
    while( $authors_iterator->iterate() ) {
	$html .= '<li>';
	$html .= '<a href="' . get_author_posts_url( $authors_iterator->current_author->ID, $authors_iterator->current_author->user_nicename ) . '">';
	$html .= '<span class="pp-multiple-authors-name">' . $authors_iterator->current_author->display_name . '</span>';
	$html .= '<span class="pp-multiple-authors-avatar">' . multiple_authors_get_avatar( $authors_iterator->current_author, 25 ) . '</span>';
	$html .= '</a>';
	$html .= '</li>';
    }

    $html .= '</ul>';

    return $html;
}

Your filter will receive three parameters:

  1. $html: string This is the default markup
  2. $authors_iterator This is an instance of the class PublishPress\Addon\Multiple_authors\Classes\Authors_Iterator
  3. $target: string This is the target of the author box (the_content, widget, shortcode, action)

Related Articles

Get professional publishing tools for WordPress! Get PublishPress

[i]
[i]