I am creating simple WP_Widget plugin and I want to add one filed to form function inside it. I want to allow user to pick some photo from wordpress media. I know how to implement input text, textarea or checkboxes but I don't know how to write field from wordpress media.

function form:

    <label for="<?php echo esc_attr( $this->get_field_id( 'card_two_desc' ) ); ?>"><?php esc_attr_e( 'Card #2 Description:', 'text_domain' ); ?></label> 
    <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'card_two_desc' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'card_two_desc' ) ); ?>" type="file" value="<?php echo esc_attr( $card_two_desc ); ?>"></input>

Update function:

$instance['card_two_desc'] = ( ! empty( $new_instance['card_two_desc'] ) ) ? sanitize_text_field( $new_instance['card_two_desc'] ) : '';

and I want to simpy display this value here:

<div class="card">
            <img src="<?php echo $instance['card_two_desc'] ?>" alt="">
            <h3 class="card__title"><?php echo $instance['card_one'] ?></h3>
            <p class="card__description"><?php echo $instance['card_one_desc'] ?></p>


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.