Add shortcode to display WordPress Sidebars

TIPS

Nov 23, 2020 | Divi Tips | 0 comments

Add the following PHP code to your child theme functions.php file.
[php]
// add shortcode for sidebars - use this format [get_sidebar name="Your Sidebar Name"]
function sidebar_shortcode($atts, $content="null"){
  extract(shortcode_atts(array('name' => ''), $atts));

  ob_start();
  get_sidebar($name);
  $sidebar= ob_get_contents();
  ob_end_clean();

  return $sidebar;
}
add_shortcode('get_sidebar', 'sidebar_shortcode');
[/php]

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

More Tips

Ad - Web Hosting from SiteGround - Crafted for easy site management. Click to learn more.

Cloudways Hosting

WPEngine Hosting

Pressable Hosting

AccuWeb Hosting

Ask the Divi Guy a Question

"*" indicates required fields