Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

LSSC Featured Widget

class Sidebar_Feature extends WP_Widget {

	public function __construct() {

		parent::__construct(
			'sidebar-feature',
			__( 'Sidebar Feature', 'lssc' ),
			array(
				'description' => __( 'Feature content in sidebars', 'lssc' ),
				'classname'   => 'lssc-sidebar-feature',
			)
		);

	}

	public function widget( $args, $instance ) {

		$title = apply_filters( 'widget_title', $instance['title'] );
		 
		// before and after widget arguments are defined by themes
		echo $args['before_widget'];
		if ( ! empty( $title ) )
		echo $args['before_title'] . $title . $args['after_title'];
		 
		// This is where you run the code and display the output
		echo __( 'Hello, World!', 'wpb_widget_domain' );
		echo $args['after_widget'];

	}

	public function form( $instance ) {

		// Set default values
		$instance = wp_parse_args( (array) $instance, array( 
			'lssc_sidebartext' => '',
			'lssc_sidebarimage' => '',
		) );

		// Retrieve an existing value from the database
		$lssc_sidebartext = !empty( $instance['lssc_sidebartext'] ) ? $instance['lssc_sidebartext'] : '';
		$lssc_sidebarimage = !empty( $instance['lssc_sidebarimage'] ) ? $instance['lssc_sidebarimage'] : '';

		// Form fields
		echo '<p>';
		echo '	<label for="' . $this->get_field_id( 'lssc_sidebarText' ) . '" class="lssc_sidebarText_label">' . __( 'Featured text', 'lssc' ) . '</label>';
		echo '	<input type="text" id="' . $this->get_field_id( 'lssc_sidebarText' ) . '" name="' . $this->get_field_name( 'lssc_sidebarText' ) . '" class="widefat" placeholder="' . esc_attr__( 'Enter featured text', 'lssc' ) . '" value="' . esc_attr( $lssc_sidebarText ) . '">';
		echo '	<span class="description">' . __( 'Add text to sidebar feature', 'lssc' ) . '</span>';
		echo '</p>';

		echo '<p>';
		echo '	<label for="' . $this->get_field_id( 'lssc_sidebarImage' ) . '" class="lssc_sidebarImage_label">' . __( 'Image URL', 'lssc' ) . '</label>';
		echo '	<input type="url" id="' . $this->get_field_id( 'lssc_sidebarImage' ) . '" name="' . $this->get_field_name( 'lssc_sidebarImage' ) . '" class="widefat" placeholder="' . esc_attr__( 'url', 'lssc' ) . '" value="' . esc_attr( $lssc_sidebarImage ) . '">';
		echo '	<span class="description">' . __( 'Add an image to the sidebar feature', 'lssc' ) . '</span>';
		echo '</p>';

	}

	public function update( $new_instance, $old_instance ) {

		$instance = $old_instance;

		$instance['lssc_sidebartext'] = !empty( $new_instance['lssc_sidebartext'] ) ? strip_tags( $new_instance['lssc_sidebartext'] ) : '';
		$instance['lssc_sidebarimage'] = !empty( $new_instance['lssc_sidebarimage'] ) ? strip_tags( $new_instance['lssc_sidebarimage'] ) : '';

		return $instance;

	}

}

function lssc_register_widgets() {
	register_widget( 'Sidebar_Feature' );
}
add_action( 'widgets_init', 'lssc_register_widgets' );