Last active
December 18, 2015 04:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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