Adding Co Authors Plus Functionality into Bricks

This will allow you to use “Co Authors Plus” in Bricks easily, it basically adds all the co authors like it would if you used to default author for the main author of a post

// Register the {all_authors} dynamic tag for Bricks Builder
add_filter( 'bricks/dynamic_tags_list', 'add_all_authors_tag_to_builder' );
function add_all_authors_tag_to_builder( $tags ) {
    $tags[] = [
        'name'  => '{all_authors}',  // Tag name
        'label' => 'All Authors',    // Label for the tag
        'group' => 'Co-Authors',     // Optional grouping
    ];

    return $tags;
}

// Process the {all_authors} tag and retrieve authors
add_filter( 'bricks/dynamic_data/render_tag', 'get_all_authors_for_bricks', 10, 3 );
function get_all_authors_for_bricks( $value, $post, $tag ) {
    if ( '{all_authors}' !== $tag ) {
        return $value;
    }

    if ( function_exists( 'get_coauthors' ) ) {
        $authors = get_coauthors();
        $author_names = [];

        foreach ( $authors as $author ) {
            $author_names[] = '<span class="author-name">' . esc_html( $author->display_name ) . '</span>';
        }

        return implode( ', ', $author_names );
    }

    return '<span class="author-name">' . esc_html( get_the_author() ) . '</span>'; // Fallback for single author
}


// Ensure that the {all_authors} tag is replaced in content
add_filter( 'bricks/dynamic_data/render_content', 'render_all_authors_in_content', 20, 3 );
add_filter( 'bricks/frontend/render_data', 'render_all_authors_in_content', 20, 2 );
function render_all_authors_in_content( $content, $post, $context = 'text' ) {
    if ( strpos( $content, '{all_authors}' ) === false ) {
        return $content; // Return content unchanged if {all_authors} isn't found
    }

    // Capture the co-authors and replace the dynamic tag with the output
    $my_value = get_all_authors_for_bricks( '', $post, '{all_authors}' );

    // Debugging output for the final value
    error_log( 'Final All Authors Value: ' . $my_value ); // Logs the final value to debug.log

    return str_replace( '{all_authors}', $my_value, $content );
}

I made this with the help of chatgpt

i hope this is ok i post it here as im sure others would like to use this too