godaddy-wordpress/primer

Problems using your 'godaddy_persistent_hero'

lukefivedev opened this issue · 2 comments

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' );`

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' );

}

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