Last active
December 16, 2015 18:07
-
-
Save jlavoie13/2394d72bb9d49624ce8a to your computer and use it in GitHub Desktop.
Tuckaway H1
This file contains hidden or 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 | |
/** | |
* H1 Tag Template | |
* | |
* This is a tuckaway H1 tag for SEO purposes. | |
*/ | |
// Set Variables | |
$h1_field = 'h1_tag'; // the field name defined in acf | |
$default_posttype = 'News'; // ex. Posts or News | |
if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) && is_home() ) { // Blog Home | |
$current_post_id = get_option( 'page_for_posts' ); | |
if ( get_field( $h1_field, $current_post_id ) ) { | |
echo '<h1>' . get_field( $h1_field, $current_post_id ) . '</h1>'; | |
} else { | |
echo '<h1>' . get_the_title( $current_post_id ) . '</h1>'; | |
} | |
} elseif ( is_page() || is_single() ) { // Page or Single Post | |
$queried_object = get_queried_object(); | |
if ( get_field( $h1_field, $queried_object->ID ) ) { | |
echo '<h1>' . get_field( $h1_field, $queried_object->ID ) . '</h1>'; | |
} else { | |
echo '<h1>' . get_the_title( $queried_object->ID ) . '</h1>'; | |
} | |
} elseif ( is_tax() ) { // Taxonomy | |
$queried_object = get_queried_object(); | |
if ( get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) ) { | |
echo '<h1>' . get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) . '</h1>'; | |
} else { | |
echo '<h1>' . single_term_title( '', false ) . '</h1>'; | |
} | |
} elseif ( is_category() ) { // Default Category | |
$queried_object = get_queried_object(); | |
if ( get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) ) { | |
echo '<h1>' . get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) . '</h1>'; | |
} else { | |
echo '<h1>' . sprintf( __( '%1$s Categorized: %2$s', 'scaffolding' ), $default_posttype, single_cat_title( '', false ) ) . '</h1>'; | |
} | |
} elseif ( is_tag() ) { // Default Tag | |
$queried_object = get_queried_object(); | |
if ( get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) ) { | |
echo '<h1>' . get_field( $h1_field, $queried_object->taxonomy . '_' . $queried_object->term_id ) . '</h1>'; | |
} else { | |
echo '<h1>' . sprintf( __( '%1$s Tagged: %2$s', 'scaffolding' ), $default_posttype, single_tag_title( '', false ) ) . '</h1>'; | |
} | |
} elseif ( is_author() ) { // Author | |
$queried_object = get_queried_object(); | |
$author_id = $queried_object->display_name; | |
echo '<h1>' . sprintf( __( '%1$s By: %2$s', 'scaffolding' ), $default_posttype, $author_id ) . '</h1>'; | |
} elseif ( is_day() ) { // Day | |
echo '<h1>' . sprintf( __( 'Daily Archives: %s', 'scaffolding' ), get_the_time( 'l, F j, Y' ) ) . '</h1>'; | |
} elseif ( is_month() ) { // Month | |
echo '<h1>' . sprintf( __( 'Monthly Archives: %s', 'scaffolding' ), get_the_time( 'F Y' ) ) . '</h1>'; | |
} elseif ( is_year() ) { // Year | |
echo '<h1>' . sprintf( __( 'Yearly Archives: %s', 'scaffolding' ), get_the_time( 'Y' ) ) . '</h1>'; | |
} elseif ( is_archive() ) { // Archive | |
$queried_object = get_queried_object(); | |
echo '<h1>' . sprintf( __( 'Archives: %s', 'scaffolding' ), $queried_object->labels->name ) . '</h1>'; | |
} elseif ( is_search() ) { // Search | |
echo '<h1>' . sprintf( __( 'Search Results for: %s', 'scaffolding' ), esc_attr( get_search_query() ) ) . '</h1>'; | |
} elseif ( is_404() ) { // 404 | |
echo '<h1>' . __( 'Page Not Found', 'scaffolding' ) . '</h1>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment