Forcing a page layout conditionally in Genesis

If you find this free website useful – why don’t you support this with a donation? It is easy…. read more ….

Often it is prudent to force a page layout, especially the home page.

Within Genesis, the guidance is fairly scant

 

<?php
//* Do NOT include the opening php tag

//* Force content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );

//* Force sidebar-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content' );

//* Force content-sidebar-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar_sidebar' );

//* Force sidebar-sidebar-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_sidebar_content' );

//* Force sidebar-content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' );

//* Force full-width-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

But with no real guidance how do you use it?

Firstly, you may want this to apply to the front page or a specific template.

In which case just add it to your front_page.php or page_template.php, but it needs to be hooked to genesis meta (they forget to tell you this

<?php
//* Do NOT include the opening php tag

add_action( 'genesis_meta', 'bw_home_genesis_meta' );

function bw_home_genesis_meta() {

   // Force content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );

}

Some times, you may want to be more ‘conditional’ and hence you could apply similar logic in your functions.php, in the following I am using a priority of 11,  because I know the front_page template forces a lyout and by using a higher priority than the default (10) my functions.php will take priority

add_action( 'genesis_meta', 'bw_force_layout' );
function bw_force_layout() {

    if (is_home() || is_front_page()) {
      add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' ,11);
    }

}

 

 


Posted

in

, ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *