I have 2 variables in the widget form method like this →

$newsletter_title = isset( $instance['newsletter_title'] ) ? $instance['newsletter_title'] : '';
$newsletter_description = isset( $instance['newsletter_description'] ) ? $instance['newsletter_description'] : '';

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

            <label for="<?php echo $this->get_field_id('text'); ?>">
            <?php echo __('Newsletter Description:', 'charito');?>
            <textarea class="widefat" id="<?php echo $this->get_field_id('newsletter_description'); ?>" name="<?php echo $this->get_field_name('newsletter_description'); ?>" ><?php echo esc_attr($newsletter_description); ?></textarea>

and the same has been updated in the widget update method like this →

 if ( ! empty( $new_instance['newsletter_title'] ) ) {
            $instance['newsletter_title'] = sanitize_text_field( $new_instance['newsletter_title'] );

        if ( ! empty( $new_instance['newsletter_description'] ) ) {
            $instance['newsletter_description'] = sanitize_text_field( $new_instance['newsletter_description'] );

In the widget function →, I have the HTML like this →

<h2><?php _e('MARKETING TIPS','text_domain'); ?></h2>
                        <p><?php _e('Latest Heading deliver to you','text_domain'); ?></p>

Instead of marketing tips, I have to print the dynamic value of $newsletter_title. How can I do that? I tried many echo options none work?

similarly, we have to do for this hard coded text also →

Latest Heading deliver to you → we have to print the value stored in $newsletter_description

Read more here: How to to Print the information saved and updated in widget update function


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: