Last active
August 29, 2015 14:03
-
-
Save hellofromtonya/e76ef3ce63dc17556dff to your computer and use it in GitHub Desktop.
Add Icon to Post Title for Genesis
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
add_filter('genesis_post_title_output', 'lunarwp_add_icon_to_post_title', 10, 1); | |
/** | |
* Add icon to the Post Title | |
* | |
* @since 1.0.0 | |
* | |
* @param string $title Post Title HTML | |
* @return string Amended Post Title HTML | |
*/ | |
function lunarwp_add_icon_to_post_title( $title ) { | |
$categories = get_the_category(); | |
if ( empty( $categories ) ) return $title; | |
foreach ( $categories as $category ) { | |
$icon = sprintf( '<span class="icon-cat-%s"></span>', $category->slug ); | |
break; | |
} | |
if ( false === strpos( $title, 'rel="bookmark"' ) ) { | |
$title = str_replace( 'itemprop="headline">', 'itemprop="headline">' . $icon, $title ); | |
} else { | |
$title = str_replace( 'rel="bookmark">', 'rel="bookmark">' . $icon, $title ); | |
} | |
return $title; | |
} |
Line 13 - Added the missing closing parenthesis.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added lines 12 & 14 and replaced the foreach with $categories - this will eliminate the error that can occur if there are no categories for a given article.