0
<?php echo $args['before_title'].$title.$args['after_title'];   ?>

The above code generates the widget title. Here is it's admin image →enter image description here

Here is additional code:

<p>
                <label for="<?php echo $this->get_field_id('title'); ?>">
                    <?php echo __('Main Title:', 'charito');?>
                    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
                </label>
            </p>

Issue: when I empty the title in the backend and press save than by default its take the title 'SUBSCRIBE' Ideally it should be blank. what is causing this issue?

  • In both cases, where is $title being set, and what’s the code for saving the widget? – Jacob Peattie Sep 23 '17 at 6:24
  • You mean this → ` $title = empty($instance['title']) ? __("Subscribe",'charito') : apply_filters('widget_title', $instance['title']);` – The WP Intermediate Sep 23 '17 at 6:45
  • or This → ` $title = strip_tags($instance['title']); ` – The WP Intermediate Sep 23 '17 at 6:45
  • 4
    $title = empty($instance['title']) ? __("Subscribe",'charito') : apply_filters('widget_title', $instance['title']); This line specifically sets the title to Subscribe if no title is set. It's doing exactly what you've told it to do. Why is this line there if you don't want this behaviour? – Jacob Peattie Sep 23 '17 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.