Home>Support>Custom widget

Custom widget

Greetings. I need help. I created a widget using this instruction – https://siteorigin.com/docs/widgets-bundle/getting-started/creating-a-widget/. But after all the actions, no widget appears.

I did the following

1. I went to the plugins folder and created a folder there called extend-widgets-bundle
2. In this folder I created a file extend-widgets-bundle.php and placed the following code in the file

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 10 months, 12 days ago Сергей Хомутов
    /*
    Widget Name: Hello world widget
    */
    function add_my_awesome_widgets_collection($folders){
        $folders[] = plugin_dir_path(__FILE__).'extra-widgets/';
        return $folders;
    }
    add_filter('siteorigin_widgets_widget_folders', 'add_my_awesome_widgets_collection');
  2. 10 months, 12 days ago Сергей Хомутов

    3. In the extend-widgets-bundle folder I created another extra-widgets folder
    4. In the extra-widgets folder I created another hello-world-widget folder
    5. In the hello-world-widget Folder I created a file hello-world-widget.php in which I placed the following code

    /*
    Widget Name: Hello world widget
    Description: An example widget which displays 'Hello world!'.
    Author: Me
    Author URI: http://example.com
    Widget URI: http://example.com/hello-world-widget-docs,
    Video URI: http://example.com/hello-world-widget-video
    */
    
    class Hello_World_Widget extends SiteOrigin_Widget {
    
        function get_template_name($instance) {
            return '';
        }
    
        function get_style_name($instance) {
            return '';
        }
    }
    
    siteorigin_widget_register('hello-world-widget', __FILE__, 'Hello_World_Widget');
    
    function __construct() {
        //Here you can do any preparation required before calling the parent constructor, such as including additional files or initializing variables.
    
        //Call the parent constructor with the required arguments.
        parent::__construct(
        // The unique id for your widget.
            'hello-world-widget',
    
            // The name of the widget for display purposes.
            __('Hello World Widget', 'hello-world-widget-text-domain'),
    
            // The $widget_options array, which is passed through to WP_Widget.
            // It has a couple of extras like the optional help URL, which should link to your sites help or support page.
            array(
                'description' => __('A hello world widget.', 'hello-world-widget-text-domain'),
                'help'        => 'http://example.com/hello-world-widget-docs',
            ),
    
            //The $control_options array, which is passed through to WP_Widget
            array(
            ),
    
            //The $form_options array, which describes the form fields used to configure SiteOrigin widgets. We'll explain these in more detail later.
            array(
                'text' => array(
                    'type' => 'text',
                    'label' => __('Hello world! goes here.', 'siteorigin-widgets'),
                    'default' => 'Hello world!'
                ),
            ),
    
            //The $base_folder path string.
            plugin_dir_path(__FILE__)
        );
    }
    
    function get_template_name($instance) {
        return 'hello-world-template';
    }
    
    function get_template_dir($instance) {
        return 'hw-templates';
    }

    6. In the hello-world-widget folder I created another folder hw-templates in which I added the file hello-world-template.php in which I placed the following code

     echo wp_kses_post($instance['text']) 

    After doing all the steps, the widget I created does not appear anywhere. What do I need to do so that this widget appears in the builder and I can use it?

  3. 10 months, 11 days ago Andrew Misplon
    Hi, I Work Here

    Hi Сергей

    Thanks for posting your question.

    If you have enabled your widget at Plugins > SiteOrigin Widgets and the issue persists, please upload a copy of your plugin to any cloud location like Drive or WeTransfer and share the link here. I’ll have our developer, Alex, take a look.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More