Replace Sidebar Using Genesis Framework

If you use the Genesis framework and you want to replace a sidebar, you can use the snippet below:

add_action( 'get_header', 'wpkb_replace_sidebar' );

function wpkb_replace_sidebar() {
    if ( is_home() || is_archive() || is_search() ) {
        // Change primary to facet sidebar
        remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // Remove primary sidebar
        add_action( 'genesis_sidebar', 'wpkb_do_sidebar' ); // Add desired sidebar

        function wpkb_do_sidebar() {
            dynamic_sidebar( 'my_sidebar' );
        }
    }
}