Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
davilera
/
0-sidebar-shortcode.php
Secret
Created
August 1, 2018 14:18
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Raw
0-sidebar-shortcode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
<?php
/*
Plugin Name: Sidebar Shortcode
Description: Two shortcodes for WordPress that will allow you to call sidebars or widget areas from the WordPress editor.
Plugin URI: https://github.com/jcasabona/Sidebar-Shortcode
Author: Joe Casabona
Author URI: http://casabona.org
Version: 1.1
License: GPL2
*/
function jc_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');
/** If you want just widgets and not the entire template! **/
function jc_widgets_shortcode($atts, $content=null){
extract(shortcode_atts(array('name' => ''), $atts));
if (is_active_sidebar($name)){
ob_start();
dynamic_sidebar($name);
$widgets= ob_get_contents();
ob_end_clean();
return $widgets;
}else{
return "";
}
}
add_shortcode('get_widgets', 'widgets_shortcode');
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.