Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Last active December 18, 2015 04:49
Show Gist options
  • Save rfmeier/5728682 to your computer and use it in GitHub Desktop.
Save rfmeier/5728682 to your computer and use it in GitHub Desktop.
Display the first category before the content wrap in Genesis for a single post.
<?php
add_action( 'genesis_before_content_sidebar_wrap', 'single_display_category_title' );
/**
* Callback for Genesis 'genesis_before_content_sidebar_wrap' action.
*
* @package Genesis
* @category Post Template
* @author Ryan Meier http://www.rfmeier.net
*
* @global object $post The current post within the loop.
* @return none exit function
*/
function display_category_title(){
// scope in the current post object
global $post;
// get all the categories for the post
$categories = get_the_category( $post->ID );
// if invalid categories, return
if( empty( $categories ) )
return;
// get the 0th category in the array
$category = array_shift( $categories );
// display the title
printf( '<h1 class="category-title">%s</h1>', esc_html( $category->name ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment