Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Widget Area Shortcode
- Description: A shortcode to display a widget area.
- Plugin URI: https://www.damiencarbery.com
- Version: 0.1
- Author: Damien Carbery
- */
- defined( 'ABSPATH' ) || exit;
- add_action( 'widgets_init', 'dcwd_register_sidebar_for_shortcode' );
- function dcwd_register_sidebar_for_shortcode() {
- $args = array(
- 'name' => 'Shortcode',
- 'id' => 'sidebar-shortcode',
- 'description' => 'Sidebar that will be displayed via a shortcode.',
- 'class' => 'sidebar-shortcode',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h2 class="widgettitle">',
- 'after_title' => '</h2>'
- );
- register_sidebar( $args );
- }
- add_shortcode( 'sidebar_display', 'dcwd_sidebar_display' );
- function dcwd_sidebar_display() {
- if ( is_active_sidebar( 'sidebar-shortcode' ) ) {
- ob_start();
- dynamic_sidebar( 'sidebar-shortcode' );
- return ob_get_clean();
- }
- return '<p>sidebar not active.</p>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement