Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 23, 2015 03:59
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 robneu/6577556 to your computer and use it in GitHub Desktop.
Save robneu/6577556 to your computer and use it in GitHub Desktop.
If you don't like backstretch, you might prefer to display a normal image instead. Once you've removed the enqueue scripts functions from front-page.php, all you need to do is output the background image by hooking it after the header.
<?php
//* Enqueue scripts
add_action( 'wp_enqueue_scripts', 'minimum_front_page_enqueue_scripts' );
function minimum_front_page_enqueue_scripts() {
//* Load scripts only if custom background is being used
if ( ! get_background_image() )
return;
//* Enqueue Backstretch scripts
wp_enqueue_script( 'minimum-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'minimum-backstretch-set', get_bloginfo('stylesheet_directory').'/js/backstretch-set.js' , array( 'jquery', 'minimum-backstretch' ), '1.0.0' );
wp_localize_script( 'minimum-backstretch-set', 'BackStretchImg', array( 'src' => get_background_image() ) );
//* Add custom body class
add_filter( 'body_class', 'minimum_add_body_class' );
}
//* Minimum custom body class
function minimum_add_body_class( $classes ) {
$classes[] = 'minimum';
return $classes;
}
<?php
//* Add widget support for homepage if widgets are being used
add_action( 'genesis_meta', 'minimum_front_page_genesis_meta' );
function minimum_front_page_genesis_meta() {
//* Remove entry meta in entry footer and Genesis loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
//* Add Genesis grid loop
add_action( 'genesis_loop', 'minimum_grid_loop_helper' );
add_action( 'genesis_after_header', 'minimum_home_image', 9 );
//* Remove entry footer functions
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
//* Force full width content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
if ( is_active_sidebar( 'home-featured-1' ) || is_active_sidebar( 'home-featured-2' ) || is_active_sidebar( 'home-featured-3' ) || is_active_sidebar( 'home-featured-4' ) ) {
//* Add Home featured Widget areas
add_action( 'genesis_before_content_sidebar_wrap', 'minimum_home_featured', 15 );
}
}
function minimum_home_image() {
//* Do nothing if we have no background image.
if ( ! get_background_image() ) {
return;
}
//* Display the background image.
echo '<img class="custom-bg" src="' . get_background_image() . '" title="' . get_bloginfo( 'name' ) . '" alt="' . get_bloginfo( 'name' ) . '" />';
}
//* Add markup for homepage widgets
function minimum_home_featured() {
printf( '<div %s>', genesis_attr( 'home-featured' ) );
genesis_structural_wrap( 'home-featured' );
genesis_widget_area( 'home-featured-1', array(
'before'=> '<div class="home-featured-1 widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-featured-2', array(
'before'=> '<div class="home-featured-2 widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-featured-3', array(
'before'=> '<div class="home-featured-3 widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-featured-4', array(
'before'=> '<div class="home-featured-4 widget-area">',
'after' => '</div>',
) );
genesis_structural_wrap( 'home-featured', 'close' );
echo '</div>'; //* end .home-featured
}
//* Genesis grid loop
function minimum_grid_loop_helper() {
if ( function_exists( 'genesis_grid_loop' ) ) {
genesis_grid_loop( array(
'features' => 0,
'feature_image_size' => 0,
'feature_content_limit' => 0,
'grid_image_size' => 0,
'grid_content_limit' => 250,
'more' => __( '[Read more]', 'minimum' ),
) );
} else {
genesis_standard_loop();
}
}
//* Run the Genesis loop
genesis();
.home .custom-bg {
display: block;
margin: 60px auto 0;
margin: 6rem auto 0;
}
.home .site-tagline {
margin-top: 0;
}
/*
Add this rule within the already existing @media only screen and (max-width: 1023px)
You only need to add the .home .custom-bg rule. The rest is just to illustrate how the rule
should be placed in the existing media query.
---------------------------------------------------------------------------------------------------- */
@media only screen and (max-width: 1023px) {
.home .custom-bg {
margin: 0 auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment