Adding custom contents to different places using Widgets in Genesis is simple and can be achieved using plugins or some line of codes.
Sidebar or Widget Area?
Since Genesis version 2.1.0, there is a new function genesis_register_widget_area that is identical to genesis_register_sidebar . There are few difference between them
Widget area can be registered anywhere using Genesis hooks while a sidebar is limited to display on their preferred layout setting. We Generally remove the primary sidebar while adding custom sidebar in Genesis site whereas custom widgets are registered without removing anything from default.
If you’re registering a widget area that’s not intended as a sidebar, you might find that the terminology of genesis_register_widget_area makes more sense.
However, there is no difference between them and usage is the same and You can use the genesis_register_sidebar to create front page widget sections or custom widget sections.
How to Create a Widget Area?
Step 1. Create and Register a Wiget Area. Add this in functions.php
//* Register a Simple Widget area genesis_register_sidebar( array( 'id' => 'simple-widget', 'name' => __( 'Simple Widget', 'wpize' ), 'description' => __( 'This is a simple widget area.', 'wpize' ), ) );
Step 2. Hook the Widget and Display it. Add this in functions.php
//* Add the Simple widget using Genesis Hook and Display it for me add_action( 'genesis_before_content', 'wpize_simple_widget_content' ); function wpize_simple_widget_content() { genesis_widget_area ('simple-widget', array( 'before' => '<div class="simple-widget widget-area"><div class="wrap">', 'after' => '</div></div>', ) ); }
Additional:- Add some styles. Paste it in your CSS file.
.simple-widget { border: 1px solid rgba(240,245,250,.6); padding: 20px; margin: 10px; width: auto; background: #fafafa; }
Want the Widget for the single post only? Yup, we can do it using Conditional tags.
Example:- Replace the Step 2. with this snippet.
//* Add this Simple widget using Genesis Hook and Conditional Tag add_action( 'genesis_before_content', 'wpize_simple_widget_content' ); function wpize_simple_widget_content() { if ( is_singular('post') ) { genesis_widget_area ('simple-widget', array( 'before' => '<div class="simple-widget widget-area"><div class="wrap">', 'after' => '</div></div>', ) ); } }
It’s done 🙂