Buy All 48 Premium WordPress Themes for $54.99

How to Add Widgets inside Slides

Widgets in Slides

By default our themes comes with Customizer options for Slides content such as Slide Background Image, Title, Text, Link URL, etc. In some cases you may want to insert widgets as slide content. Here is a guide how it can be done:

Login to your Admin Panel and navigate to Left Menu -> Appearance -> Editor, then open functions.php for editing.

Below the following code:

// II. Register Widget Areas

Insert:

// II. Register Widget Areas

for ($i = 1; $i <= 5; ++$i) {

  // Add Slide #i Widget
  register_sidebar( array (
   'name' =>
  sprintf( esc_html__( 'Slide #%s',
              'tishonator' ), $i ),
   'id'    =>  'slide-'.$i.'-widget-area',
   'description'   => 
sprintf( esc_html__( 'The Slide #%s widget area',
'tishonator' ), $i ),
        'before_widget'  =>  '',
        'after_widget'   =>  '',
        'before_title'   =>  '<h2>',
        'after_title'   =>  '</h2>',
      ) );      
}

Then below the following code:

<h2><?php echo $slideTitle; ?></h2>

insert:

<h2><?php echo $slideTitle; ?></h2>

<?php dynamic_sidebar( 'slide-'.$i.'-widget-area' ); ?>

Then Navigate to Left Menu -> Appearance -> Widgets and Insert widget you want in some of the available Slide # widget areas:

insert widget in slide

and Save changes.

About the Author

Tihomir Ivanov is a WordPress and Salesforce Commerce Cloud (SFCC) developer, founder of tishonator.com, a fan of Linux and Open Source, Minimalism (in Design and Life), Sci-fi, Fantasy, Classic and History books :)

Leave a Reply