customize widget wordpress code example

Example 1: custom widget area wordpress

<?php
  
 /**
 * Register our sidebars and widgetized areas. - Most times you can place this instead your fuction file.
 *
 */
function arphabet_widgets_init() {

	register_sidebar( array(
		'name'          => 'Home right sidebar',
		'id'            => 'home_right_1',
		'before_widget' => '<div>',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="rounded">',
		'after_title'   => '</h2>',
	) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>
  
/* show sidebar - template file */  
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
	<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
		<?php dynamic_sidebar( 'home_right_1' ); ?>
	</div><!-- #primary-sidebar -->
<?php endif; ?>

Example 2: dynamic widget of wordpress

/* functions.php file */
function twentyseventeen_widgets_init() {
	register_sidebar(
		array(
			'name'          => __( 'Blog Sidebar', 'twentyseventeen' ),
			'id'            => 'sidebar-1',
			'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
    }
    add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
    
    
    /*  footer-widgets.php file  */
    <aside class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Footer', 'twentyseventeen' ); ?>">
			<div class="container">
				<div class="nw_prt">
					<div class="row">
						<div class="col-md-3">
							<div class="nw">
								<?php dynamic_sidebar('footer-1');?>
							</div>
						</div>
						<div class="col-md-3">
							<div class="nw">
								<?php dynamic_sidebar('footer-2');?>
							</div>
						</div>
                    </div>
				</div>
			</div>		
	</aside><!-- .widget-area -->

Tags:

Php Example