This code enables you to add the Soliloquy slider before the header to any Genesis child theme.
Tested using the Academy Pro & Genesis Sample child themes by StudioPress.
Installation Guide
There’s 2 steps :
Step 1 : Install the Soliloquy slider and create a slider named Slider.
Step 2 : Add the following PHP code to the end of your child themes functions file.
add_action( 'genesis_before_header', 'add_slider' );
function add_slider() {
if ( function_exists( 'soliloquy' ) ) {
soliloquy( 'slider', 'slug' );
}
}
Video Installation Guide
Shows you how to install, setup and add the code required to display the slider in different positions and on specific pages in any Genesis child theme.
Change Position of Slider
Change the genesis_before_header
hook in the above code to any other Genesis hook like this example which changes the hook to genesis_after_header
:
add_filter( 'genesis_after_header', 'add_slider' );
function add_slider() {
if ( function_exists( 'soliloquy' ) ) {
soliloquy( 'slider', 'slug' );
}
}
Only Show Slider On Specific Pages
Add any conditional tag to the code like this :
add_filter( 'genesis_before_header', 'add_slider' );
function add_slider() {
if ( ! is_front_page() ) {
return;
}
if ( function_exists( 'soliloquy' ) ) {
soliloquy( 'slider', 'slug' );
}
}
The above version of the code only displays the slider on the front page. Swap out the is_front_page()
conditional tag with any other conditional to only show the slider on specific pages or posts.
And why is a “filter” being used instead of a “hook”?
Typo as i was also writing a filter function at the same time and copied the first 2 lines to save time when testing. I forgot to update the embedded code which i have now done. add_filter is also a filter hook which will work, but add_action is the correct method.
if ( ! is_front_page() ) {
return;
}
That to me reads, if Not True (!) that we are on the front page(is_front_page), then do nothing (return).
Does that “return” cause the function to end, meaning that the second “if” statement never runs?
Yes, if its not the front page then end execution so function_exists never runs.
You can also write the code like this :
I see. Thanks!