Skip to content

Instantly share code, notes, and snippets.

@jamiemitchell
Last active September 7, 2016 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiemitchell/d04ab7920386904e8085 to your computer and use it in GitHub Desktop.
Save jamiemitchell/d04ab7920386904e8085 to your computer and use it in GitHub Desktop.
Add page title on pages if has featured image
<?php
/* Add page title on pages if has featured image
------------------------------------------------------------ */
add_action ( 'genesis_meta', 'altitude_add_page_title' );
function altitude_add_page_title() {
if ( has_post_thumbnail() && is_page() && !is_page_template() ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
add_action( 'genesis_after_header', 'altitude_open_post_title', 1 );
add_action( 'genesis_after_header', 'genesis_do_post_title', 2 );
add_action( 'genesis_after_header', 'altitude_close_post_title', 3 );
add_filter( 'body_class', 'altitude_inner_featured_body_class' );
}
}
// Add opening div and background image
function altitude_open_post_title() {
if ( $image = genesis_get_image( 'format=url&size=full' ) ) {
printf( '<div class="image-header" style="background-image: url(%s);"><div class="image-header-wrap"><div class="wrap">', $image );
}
}
// Add closing div
function altitude_close_post_title() {
echo '</div></div></div>';
}
// Add body class
function altitude_inner_featured_body_class( $classes ) {
$classes[] = 'featured-section';
return $classes;
}
/* Page title
--------------------------------------------- */
.page.featured-section .site-inner {
margin-top: 70px;
}
.image-header {
min-height: 400px;
background-attachment: fixed;
background-color: #fff;
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
.image-header-wrap {
background: -moz-linear-gradient(top, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.5) 30%, rgba(0,0,0,0.8) 80%, rgba(0,0,0,0.9) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.2)), color-stop(30%,rgba(0,0,0,0.5)), color-stop(80%,rgba(0,0,0,0.8)), color-stop(100%,rgba(0,0,0,0.9)));
background: -webkit-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.5) 30%,rgba(0,0,0,0.8) 80%,rgba(0,0,0,0.9) 100%);
background: -o-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.5) 30%,rgba(0,0,0,0.8) 80%,rgba(0,0,0,0.9) 100%);
background: -ms-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.5) 30%,rgba(0,0,0,0.8) 80%,rgba(0,0,0,0.9) 100%);
background: linear-gradient(to bottom, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.5) 30%,rgba(0,0,0,0.8) 80%,rgba(0,0,0,0.9) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#33000000', endColorstr='#e6000000',GradientType=0 );
}
.image-header .entry-title {
color: #fff;
font-size: 72px;
margin: 300px 0 250px;
text-align: center;
}
@media only screen and (max-width: 1023px) {
.front-page .site-header,
.page.featured-section .site-header {
background-color: #000;
}
.front-page .site-header > .wrap,
.page.featured-section .site-header > .wrap {
border: none;
}
.image-header {
background-attachment: scroll;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment