Your cart is currently empty!
Icon Above Post Titles
โ
by
The PHP code in this post, once added to your child themes functions file, enables you to display icon before your single post titles like you see in the following screenshot:
add_action( 'wp_enqueue_scripts', 'bg_enqueue_ionicons' );
function bg_enqueue_ionicons() {
wp_enqueue_style( 'ionicons', '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', array(), CHILD_THEME_VERSION );
}
add_action( 'genesis_entry_header', 'icon_before_post_title', 5 );
function icon_before_post_title() {
if ( is_singular( 'post' ) ) {
echo '<h1><i class="ion-fork entry-title"></i></h1>';
}
}
Different Icon For Each Category
This code enables you to add a different icon above post titles for single posts in different categories.
add_action( 'genesis_entry_header', 'icon_before_post_title', 5 );
function icon_before_post_title() {
if ( ! is_singular( 'post' ) )
return;
if ( in_category( 'food' ) ) {
echo '<h1><i class="ion-fork entry-title"></i></h1>';
}
elseif ( in_category( 'wine' ) ) {
echo '<h1><i class="ion-wineglass entry-title"></i></h1>';
}
}
The code loads ion icons and hooks in the icon before the single post entry title using the genesis_entry_header hook with a 3rd parameter for positioning priority of 5.
The code also uses the is_singular conditional tag so it only executes on single posts and not single pages.
Free
$0
Access only to all free tutorials per month.
Tutorial Request
Includes code guarantee and coding support.
Monthly
$75
Access to 10 premium tutorials per month.
Tutorial Request
Includes code guarantee and coding support.
Yearly
$500
Access to 15 premium tutorials per month.
Monthly Tutorial Request
Includes code guarantee and priority coding support.
Was This Tutorial Helpful?