Example:
<?php class Title_Fields_Widget extends WP_Widget { function __construct() { // Instantiate the parent object $widget_ops = array( 'classname' => 'widget_title_fields_entries', 'description' => esc_attr__('Title Field Widget - Created by deshisoft', 'eye-theme') ); $control_ops = array( 'width' => 275 ); parent::__construct( false, 'Title Field Widget', $widget_ops, $control_ops ); } function widget( $args, $instance ) { extract( $args ); // Widget output $title = apply_filters('widget_title', $instance['title']); echo $before_widget; echo '<div >'. esc_attr($title) .'</div>'; echo $after_widget; } function update( $new_instance, $old_instance ) { // Save widget options $instance = array(); $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); return $instance; } function form( $instance ) { // Output admin widget options form $title = $instance['title']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> <?php } } function title_field_register_widgets() { register_widget( 'Title_Fields_Widget' ); } add_action( 'widgets_init', 'title_field_register_widgets' ); ?>
Theme Folder -> function.php
Add this line:
require get_template_directory() . '/inc/title_widget.php'; // inc folder name depend on your theme.