Back

Wordpress PHP

Add A Custom Widget

In your functions.php, add in this code

register_sidebar( array(
  'name' => __( 'Custom Widget Area'),
  'id' => 'custom-widget-area',
  'description' => __( 'An optional custom widget area for your site', 'twentyseventeen' ),
  'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</div>",
  'before_title' => '<h3 class="widget-title">',
  'after_title' => '</h3>',
) );
      

In the file you want to add the widget, add this code

<?php
  if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("PUT NAME OF CUSTOM WIDGET HERE") ) : ?>
<?php endif; ?>