Created
October 17, 2016 19:05
-
-
Save ndiego/d8fe00799fb9a541829ae821f8293074 to your computer and use it in GitHub Desktop.
Custom Page Title with Sub-Titles
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 our custom page title to singular pages, but not the homepage or blog page | |
if ( is_page() && ! is_home() && ! is_front_page() ) { | |
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); | |
add_action( 'genesis_after_header', 'blox_open_post_title', 1 ); | |
add_action( 'genesis_after_header', 'blox_do_page_title', 2 ); | |
add_action( 'genesis_after_header', 'blox_close_post_title', 3 ); | |
} | |
// Custom title opener | |
function blox_open_post_title() { | |
echo '<div class="page-title"><div class="wrap">'; | |
} | |
// Custom title closer | |
function blox_close_post_title() { | |
echo '</div></div>'; | |
} | |
// Custom page title and subtitle (subtitle is a custom field - blox_subtitle) | |
function blox_do_page_title() { | |
$id = get_the_ID(); | |
$title = get_the_title(); | |
$subtitle = get_post_meta( $id, 'blox_subtitle', true ); | |
// If not title, return | |
if ( 0 === mb_strlen( $title ) ) { | |
return; | |
} | |
echo '<h1 class="entry-title" itemprop="headline">' . $title . '</h1>'; | |
if ( ! empty( $subtitle ) ) { | |
echo '<p class="entry-subtitle">' . $subtitle . '</h1>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment