Customizing the Author Box using the Genesis Theme

I had some consulting work come in – task was pretty straightforward, then again what
exactly is “straightfoward.” In software though, nothing is ever “straightforward”, though
that word gets used a lot to describe something pretty close to being straightforward but not
exactly so.

Alright anyway, I was working off a Genesis theme. Themes, templates, architecture. I think
these terms are all synonymous, the keyword really here is architecture. There are some bad ones,
good ones and terrible ones. Genesis in my opinion is pretty good. But what qualifies as “pretty good”, really? For starters I’d say architecture that is lightweight, modularized, and loosely coupled. Architecture where we can inject new features seamlessly.

I was working on enabling an author box on a blog page, on every single blog post – so this was to be a global implementation for a blog. It’s been a while since I’ve worked with Genesis themes but good news is there’s a pretty big community around it and chances are I would be running into a frequent feature.

The author box actually displays by default. Genesis hooks allow for moving the box in different locations of the template. Again, pretty “straightforward”. But not so. I was running into a conflict with another plugin, a related categories plugin that was taking up the same spot. So I had to figure out a way to sandwich this author box between the main content and that related posts area. So what I expected to take at least an hour to implement took roughly 3 hours. There was a lot of poking around to be had.

On to the codes…


/* Customize Single Blog Post Author Box */
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );

add_action( 'genesis_after_entry_content', 'wps_theme_author_box', 8 );
function wps_theme_author_box() {

  global $post;

	if ( is_singular('post') ) {
    $author_id = $post->post_author;
    $author_link    = get_author_posts_url( $author_id );
		$author_avatar 	= get_avatar( get_the_author_meta( 'ID' ), 70 );
		$author_name 	= get_the_author_meta( 'display_name' );
		$author_desc 	= get_the_author_meta( 'description' );
		echo '<section class="author-box">';
		echo $author_avatar;
		echo '<h4 class="author-box-title"><a href="' . esc_url( $author_link ) . '" title="About '.$author_name.'">About ' . $author_name . '</a></h4>';
		echo '<div class="author-box-content" itemprop="description"><p>' . $author_desc . '</p></div>';
    echo '<div class="clear"></div>';
    echo '</section>';
	}
 }

 /* Display related posts plugin */
 add_action( 'genesis_entry_footer', 'manual_related_posts_plugin', 8 );
 function manual_related_posts_plugin() {
   echo do_shortcode( '[manual_related_posts]' );
 }

So I had to actually remove the related posts shortcode which was originally enabled by the plugin itself (in the settings area). So that was easy. There was only one optimal way of taking full control over this module – and I decided to use a combination of a Genesis hook and shortcode to accomplish this.

The meat of the code though is the author box and there was some customization needed, a small one though. But a small request can be literally 10 lines of code in the software realm which was the case here. And so we pass a callback function to ‘genesis_after_entry_content‘ which allows us to hook into the markup and make any modifications needed. Notice though, we first remove the author box by hooking into ‘genesis_after_entry‘ while calling the remove_action function. We then add the feature back by calling add_action.

From there it’s your usual PHP stuff and to ensure you are only implementing this on single blog posts we add a conditional if ( is_singular( ‘post’ ) ). This all worked out really nice, I was able to take full control of what the author box should look like. Should there be any additional change requests, I can just go in there and make additional modifications.

I hope this was useful for any Genesis theme newbies. We encourage you to keep immersing yourself into something new or if it’s an existing project, try learning it again – there might be something you missed along the way.