In building out a network of sites, I was struck upon by a feature of multisite I love, a feature of a theme I adore, and an inconvenience of the combination.

Author Box

StudioPress’ Genesis themes include a feature called “Author Box” which allows authors to create bios from their profiles and show them at the bottom of posts. When you have multiple authors on a site, this is a great way to make sure everyone gets credit and that they can control it.

The code to make this show up is included in most (if not all) StudioPress themes, but if you need to add it for your post archives and single posts, it looks like this:

add_filter( 'get_the_author_genesis_author_box_single', '__return_true' );
add_filter( 'get_the_author_genesis_author_box_archive', '__return_true' );

Multisite Magic

Once the code is enabled, and once someone’s written a bio, their author box shows up for all sites on the network. This is great for what I needed, as it meant everyone had control and I could just set it and forget it. The only ‘annoying’ part is it’s the same bio for all sites, so if you have wildly different sites on your network, this may not be right for you.

This does harken back to my age old comment: WordPress Multisite is for a network of somewhat related sites.

By this I mean if all the sites on your network are related, let’s say for a school, then it doesn’t matter that everyone’s bio talks about their school work. But if you combine the school with hobbies, then it gets weird to announce that the champion archer has a PhD in neuroscience. Although that is pretty cool.

Display The Author Box Anywhere

The other problem with the author box is you can only use it on pages or posts as context. Which is not what I wanted here. So I made it a shortcode.

function author_box( $atts ) {

	$user = username_exists( sanitize_user( $atts['user'] ) );

	if ( !$user ) return;

	wp_enqueue_style( 'author-box-shortcode', plugins_url( 'author-box.css', __FILE__ ) );

	$authordata    = get_userdata( $user );
	$gravatar_size = 'genesis_author_box_gravatar_size' ;
	$gravatar      = get_avatar( get_the_author_meta( 'email', $user ), $gravatar_size );
	$description   = wpautop( get_the_author_meta( 'description', $user ) );
	$username      = get_the_author_meta( 'display_name' , $user );

	$author_box    = '
		<section class="author-box author-box-shortcode">'
		. $gravatar
		. '<h4 class="author-box-title"><span itemprop="name">' . $username . '</span></h4>
		<div class="author-box-content" itemprop="description">'. $description .'</div>
		</section>
	';

	return $author_box;
}

This is obviously skewed towards Genesis themes, but realistically other than the code in $gravatar_size you can use this for any theme anywhere. The benefit of Genesis here is that most, if not all, of the CSS is done for you. The shortcode is [author-box user="ipstenu"] and it dumps out a full width user box of your named author.

Display Multiple Boxes Instead

But… What if you wanted a grid? Or a group of IDs? Taking advantage of the fact that Genesis comes with columns, the code looks like this:

function author_box( $atts ) {

	if ( $atts['users'] == '' ) return;

	wp_enqueue_style( 'author-box-shortcode', '/wp-content/mu-plugins/css/author-box.css' );

	$users = explode(',', $atts['users'] );
	$user_count = count( $users );

	$columns = 'one-half';
	if ( $user_count == 1 ) $columns = '';
	if ( $user_count % 3 == 0 ) $columns = 'one-third';

	$author_box = '<div class="author-box-shortcode">';

	foreach( $users as $user ) {
		$user = username_exists( sanitize_user( $user ) );
		if ( $user ) {
			$authordata    = get_userdata( $user );
			$gravatar_size = 'genesis_author_box_gravatar_size' ;
			$gravatar      = get_avatar( get_the_author_meta( 'email', $user ), $gravatar_size );
			$description   = wpautop( get_the_author_meta( 'description', $user ) );
			$username      = get_the_author_meta( 'display_name' , $user );

			$author_box   .= '
				<section class="author-box '. $columns .'">'
				. $gravatar
				. '<h4 class="author-box-title"><span itemprop="name">' . $username . '</span></h4>
				<div class="author-box-content" itemprop="description">'. $description .'</div>
				</section>
			';
		}
	}

	$author_box .= '</div>';

	return $author_box;
}

The shortcode here is [author-box users="ipstenu, liljimmi"] and that puts out a column of either fullwidth, half, or a third. The default is a half, and if there’s only one item, it goes to full width, but I only put in a 1/3rd check because I didn’t feel the need to cover everything. If you want to nick the CSS, StudioPress put it up online, and you can extend it as you want.

Reader Interactions

%d bloggers like this: