Create a banner across the top of the page on every page in Genesis Framework

You create a ‘Banner’ by adding a widget either in your plugin or in the themes functions.php file.

1. Register a widget

You register a widget by adding the following code

/** Register Banner Widget */
genesis_register_sidebar(array(
	'id' => 'sb-banner-above-header',
	'name' => __('Banner above header', 'theme-prefix'),
	'description' => __('This is the  banner above the header.', 'theme-prefix'),
));

2. Identify where to insert the widget

You use genesis hooks to determine where you want the new widget to display

add_action('genesis_before_header', 'sb_add_header_banner');
  • add_action
  • genesis_before_header
    • This is where the widget will be inserted. See * below this list
  • sb_add_header_banner
    • This is the function that is called when this action hook is triggered.
*Alternatives to use to place the widget somewhere else

genesis/comments.php

  • genesis_before_comments
  • genesis_comments
  • genesis_after_comments
  • genesis_before_pings
  • genesis_pings
  • genesis_after_pings
  • genesis_before_comment_form
  • genesis_comment_form
  • genesis_after_comment_form

genesis/footer.php

  • genesis_before_footer
  • genesis_footer
  • genesis_after_footer
  • genesis_after

genesis/header.php

  • genesis_doctype
  • genesis_title
  • genesis_meta
  • genesis_before
  • genesis_before_header
  • genesis_header
  • genesis_after_header

genesis/sidebar-alt.php

  • genesis_before_sidebar_alt_widget_area
  • genesis_sidebar_alt
  • genesis_after_sidebar_alt_widget_area

genesis/sidebar.php

  • genesis_before_sidebar_widget_area
  • genesis_sidebar
  • genesis_after_sidebar_widget_area

3. Create the html that will be inserted in the selected location

Insert the function that will build the html for your widget

function sb_add_header_banner()
{
	echo '<div class="sb-header-banner-wrapper">';

	genesis_widget_area('sb-header-banner', array(
		'before' => '<div class="header-banner">',
		'after' => '</div>',
	));
	echo '</div>';
}
  • note that the function name is the function that is used in Step 2.

Complete code added to plugin or functions.php

/** Register Banner Widget */
genesis_register_sidebar(array(
	'id' => 'sb-banner-above-header',
	'name' => __('Banner above header', 'theme-prefix'),
	'description' => __('This is the  banner above the header.', 'theme-prefix'),
));

/** Call the function that will insert the widget */
add_action('genesis_before_header', 'sb_add_header_banner');

/** Create the function that inserts the widget */
function sb_add_header_banner()
{
	echo '<div class="sb-header-banner-wrapper">';
	genesis_widget_area('sb-header-banner', array(
		'before' => '<div class="sb-header-banner">',
		'after' => '</div>',
	));
	echo '</div>';
}