Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created June 4, 2012 17:37
Show Gist options
  • Select an option

  • Save dongilbert/2869744 to your computer and use it in GitHub Desktop.

Select an option

Save dongilbert/2869744 to your computer and use it in GitHub Desktop.
Embed Sidebars In Content - WordPress
<?php
/**
* This code will allow you to embed a sidebar
* into a post or page or anywhere that shortcodes
* are parsed in your WordPress theme / site.
* It pairs well with Sidebar Generator
* http://wordpress.org/extend/plugins/sidebar-generator/
* Otherwise, be sure to register_sidebar('name')
*
* <samp>[sidebar position="sidebar1"]</samp>
*
* @param array mixed
* @return string The generated HTML for the sidebar
*/
add_shortcode('sidebar', 'sidebar_shortcode');
function sidebar_shortcode($atts)
{
extract(shortcode_atts(array(
'position' => null
), $atts));
if($position !== null)
{
ob_start();
dynamic_sidebar($position);
$position = ob_get_clean();
}
return $position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment