I have used the youtube video: (https://www.youtube.com/watch?v=OJdIUU1pjl4&t=1261s) to learn how to create my first custom widget. From here I have create a class with a front end display and a backend display (forms) I want to create a form to post the information, then gets saved to the database that later gets generated on the front end.

I have done this with an options page using update_option() and get_option() however, this would be a hard coded variable and since someone can use my widget in multiple places I would want each one to have a unique storage.

Here is currently what I have with php variables with no values because I am uncertain how to make my form post save the details to the database.

    //Back-end display of widget
    public function form($instance) {
        <form method="post">
            <label for="inner-text">Inside Text</label>
            <input name="inner-text" type="text">
            <label for="bg-image">Background Image</label>
            <input name="bg-image" type="image">
//front end display of widget
public function widget($args, $instance ) {
        echo $args['before_widget'];
            <div class="bg-img" style="background: url('<?= $bg_img ?>');">
                <div class="container">
                    <div class="inner-rectangle">
                        <?= $inner_text ?>

        echo $args['after_widget'];


The reason I have refrained from using get_option() is because it is a static variable and can't have a unique value for each widget.

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.