create custom widget in wordpress plugin 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: how create widget widget in wordpress

/*add this code in your child theme css style.css file */

#footer-sidebar {
	display:block;
	height: 250px;
	}
	
	#footer-sidebar1 {
	float: left;
	width: 340px;
	margin-left:5px;
	margin-right:5px;
	}
	
	#footer-sidebar2 {
	float: left;
	width: 340px;
	margin-right:5px;
	margin-left:5px;
	}
/* end style.css  */

Tags:

Php Example