• Resolved joand

    (@joand)


    HI, I added the following to register a sidebar:
    /*Register Blog Page Sidebar*/
    add_filter( ‘pt-ocdi/import_files’, ‘ocdi_import_files’ );
    function ocdi_before_widgets_import( $selected_import ) {
    $sidebars = array(
    ‘BlogPage’ => ‘Blog Page’,
    );
    update_option( ‘sbg_sidebars’, $sidebars );
    }
    add_action( ‘pt-ocdi/before_widgets_import’, ‘ocdi_before_widgets_import’ );

    And it worked – the sidebar was added. However I wanted to import widgets into this sidebar but the import is looking for the widget ID:
    et_pb_widget_area_1 : Sidebar does not exist in theme (moving widget to Inactive)

    Is there a way I can add the widget ID to the code above?

    https://www.ads-software.com/plugins/one-click-demo-import/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    you would have to create a “widgets import file” (export widgets), with this sidebar registered and populated with widgets that you want.

    Or you could edit the widget.json file to change the widget id to the one you want, but you have to be careful not to “break” the json file.

    Take care!

    Thread Starter joand

    (@joand)

    I had used the Widget Importer & Exporter plugin to create the widget file – it does have that sidebar (et_pb_widget_area_1) with the widgets populated in it – but how do I register the sidebar?

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    the sidebar is not already registered in the theme that you are importing to?

    A sidebar should be registered inside a theme or you could use a plugin for custom sidebars and use it’s filters to register a sidebar.

    You can’t register a sidebar directly in our plugin (in our action hooks), that will not work…

    Take care!

    Thread Starter joand

    (@joand)

    No, I am trying to create an install package for a child theme, and it is a new sidebar that I have registered. This is for the Divi theme which has the option build into it to register new sidebars by adding them in the WordPress Widget area.

    Your plugin did work to create the new sidebar! See the code I added in the first post – the sidebar is there when I go into the site after importing the data. I am just missing the way to match them up. (I only vaguely understand this, and I don’t know enough php to be able to figure out how to code it) It is looking for sidebar et_pb_widget_area_1 – is there not some way I can add that to the original code? Instead of BlogPage can I call it like:
    ‘et_pb_widget_area_1’ => ‘Blog Page’?

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    I don’t have experience with divi theme, so I don’t know how to create new sidebars via code. If it’s just an options update (like in your code above), then you just need to set the correct id for the newly created sidebar (et_pb_widget_area_1 in your case) and it will import the widget to the correct sidebar.

    I would recommend that you contact the divi support and ask them how to register a custom sidebar via PHP code with a predefined id.

    Take care!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding Sidebar ID’ is closed to new replies.