• Skip to main content
  • Skip to header right navigation
  • Skip to after header navigation
  • Skip to site footer
  • About Us
  • Hire Us
BizBudding logo

BizBudding Inc.

Remarkable Websites

  • Get Started Today
  • Blog
  • Podcast
  • search
  • Blogging Courses
  • Mai Solutions
  • Mai Themes
  • Showcase
  • Industries

How to display widget areas with a shortcode

Home » Blog » Design and Development » How to display widget areas with a shortcode
June 17, 2018 by BizBudding Inc.
Table of Contents[Hide][Show]
  • Step 1
  • Step 2
Reading Time: ~ < 1 minute

Recently, a member of the Genesis WP Facebook group posted a question about using shortcodes to insert widget areas inside blog posts, and the pros and cons of doing so. We’ve also had a few customers ask us about this too.

This functionality can be useful when trying to display widget areas inside the content of posts and pages, for special types of content such as ads or image sliders.

In this post, we’ll provide a handy function that makes displaying widget areas with shortcodes easy.

Step 1

Add the following code snippet to the end of your functions.php file:

add_shortcode( 'widget_area', 'prefix_widget_area_shortcode' );/** * Display widget area with shortcode. * * @since  1.0.0 * * @return string */function prefix_widget_area_shortcode( $atts ) {    $atts = shortcode_atts(        array(            'id' => '',        ),        $atts,        'widget_area'    );    ob_start();    genesis_widget_area( $atts['id'], array(        'before' => '<div class="' . $atts['id'] . ' widget-area"><div class="wrap">',        'after'  => '</div></div>',    ) );    return ob_get_clean(); }

This function registers a new shortcode with WordPress called ‘widget_area’. It accepts one argument called ‘id’ that lets you pass in the id of the widget area, which is usually the widget title in lowercase separated by dashes.

Tip: A list of all widget IDs can be output in your site’s footer by adding this snippet to your functions.php file. Remember to delete when done.

Step 2

Once the above function has been added to your theme, you can simply display a widget area using the [widget_area] shortcode and specifying the id parameter. For example, to display the Footer 1 widget area you would use:

[widget_area id="footer-1"]

That’s it, you can now display any widget area any where your site allows shortcodes.

Category: Design and DevelopmentTag: Tutorials

About BizBudding Inc.

  • View Posts

Reader Interactions

Leave a Reply Cancel reply

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

GET STARTED

  • Blogging Courses
  • Mai Theme
  • Mai Solution
  • Showcase
  • Resources

Resources

  • Shop
  • Affiliates
  • Data Protection
  • Privacy Policy
  • Terms & Conditions
  • Get Support

quick links

  • My Account
  • Cart
  • Support
  • Contact Us

Contact Details

1001 County Road 517, Suite 1
Hackettstown, NJ 07840

(877) 548-2440

Contact Us

BizBudding icon

  • Start
  • Learn
  • Build
  • Grow
  • Blog
  • Podcast
  • search

Copyright © 2010–2021 BizBudding Inc. · All Rights Reserved ♥ Work hard and be nice to people.