godaddy-wordpress / primer

Primer is a powerful theme that brings clarity to your content in a fresh design. This is the parent for all themes in the GoDaddy Primer theme family.
https://wordpress.org/themes/primer/
GNU General Public License v2.0
134 stars 36 forks source link

Problems using your 'godaddy_persistent_hero' #231

Closed lukefivedev closed 7 years ago

lukefivedev commented 7 years ago

Working on a Primer/Velux site where I would like my custom Hero text to show up in all headers. While researching, I came across your godaddy_persistent_hero that was posted here in response to another thread (issue#126). I cleared my WP cache but it does not appear to be working. Copying it below to save some time...


/** Ensure the hero widget persists across all pages
 ** @author GoDaddy
 ** @return mixed  Hero widget markup.
 */
function godaddy_persistent_hero() {
    if ( ! is_front_page() && is_active_sidebar( 'hero' ) ) {
        dynamic_sidebar( 'hero' );
    }
}
add_action( 'primer_hero', 'godaddy_persistent_hero' );`
EvanHerman commented 7 years ago

Hi @lukefivedev

It looks like the Velux theme behaves a bit differently than the parent Primer theme. I did some testing, and can confirm that using the following code snippet should get things working (although it may require some style tweaks):

/**
 * Ensure the hero widget persists across all pages
 * @author GoDaddy
 */
function godaddy_persistent_hero() {

    if ( is_front_page() || ! is_active_sidebar( 'hero' ) ) {

        return;

    }

    add_action( 'primer_after_site_header_wrapper', 'primer_add_hero' );

    add_action( 'primer_hero', 'custom_velux_hero', 20 );

}
add_action( 'wp', 'godaddy_persistent_hero' );

/**
 * Render the hero.
 * @return mixed  Hero widget markup.
 */
function custom_velux_hero() {

    dynamic_sidebar( 'hero' );

}
lukefivedev commented 7 years ago

That worked on the first try! Thank you @EvanHerman so much.