Title Field

Example:

  1. <?php
  2. class Title_Fields_Widget extends WP_Widget {
  3. function __construct() {
  4. // Instantiate the parent object
  5. $widget_ops = array(
  6. 'classname' => 'widget_title_fields_entries',
  7. 'description' => esc_attr__('Title Field Widget - Created by deshisoft', 'eye-theme')
  8. );
  9. $control_ops = array(
  10. 'width' => 275
  11. );
  12. parent::__construct( false, 'Title Field Widget', $widget_ops, $control_ops );
  13. }
  14. function widget( $args, $instance ) {
  15. extract( $args );
  16. // Widget output
  17. $title = apply_filters('widget_title', $instance['title']);
  18. echo $before_widget;
  19. echo '<div >'. esc_attr($title) .'</div>';
  20. echo $after_widget;
  21. }
  22. function update( $new_instance, $old_instance ) {
  23. // Save widget options
  24. $instance = array();
  25. $instance = $old_instance;
  26. $instance['title'] = strip_tags( $new_instance['title'] );
  27. return $instance;
  28. }
  29. function form( $instance ) {
  30. // Output admin widget options form
  31. $title = $instance['title']; ?>
  32. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  33. <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>
  34. <?php
  35. }
  36. }
  37. function title_field_register_widgets() {
  38. register_widget( 'Title_Fields_Widget' );
  39. }
  40. add_action( 'widgets_init', 'title_field_register_widgets' );
  41. ?>

Theme Folder -> function.php
Add this line:

  1. require get_template_directory() . '/inc/title_widget.php'; // inc folder name depend on your theme.

Download Title Widget Field