Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from billerickson/widget nav.php
Created February 11, 2012 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GaryJones/1799174 to your computer and use it in GitHub Desktop.
Save GaryJones/1799174 to your computer and use it in GitHub Desktop.
Add widget area before primary menu items in Genesis.
<?php
add_filter( 'genesis_nav_items', 'sws_social_icons', 10, 2 );
add_filter( 'wp_nav_menu_items', 'sws_social_icons', 10, 2 );
/**
* Adds a widget area before primary menu items.
*
* @author Bill Erickson
* @author Gary Jones
* @link https://gist.github.com/gists/1799174
*
* @param string $menu Existing menu items markup.
* @param array $args Menu arguments.
*
* @return string Amended menu items markup.
*/
function sws_social_icons( $menu, array $args ) {
if ( 'primary' !== $args['theme_location'] )
return $menu;
ob_start();
dynamic_sidebar( 'social-menu' );
return ob_get_clean() . $menu;
}
@jaredatch
Copy link

I thought using ob_start(); was bad?

@GaryJones
Copy link
Author

It's not great for performance, but if a function immediately echoes rather than returns, then there's no choice. Genesis uses it in one or two places for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment