• I have a plugin that creates a widget and widget area.
    Currently when the plugin is activated it adds the widget area as the first widget area and it adds the widgets in with the rest of the available widget.
    To add the widget a user must drag the widget to the widget area.

    How to I make the widget show up in the admin widget area by default?

    Also how to I make the widget area the last widget area instead of the first (so it shows up at the bottom of the list of widget areas in the admin view instead of at the top)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’ve not done this myself, but this is what I would try first.

    The widget status appears to be stored in the global $wp_registered_sidebars. To add a widget by default, as preliminary research, manually add the default widget, then var_dump the global and make note of the related entries. Hook an appropriate action, perhaps ‘init’ and assign the noted values to the global. That should install the widget by default.

    As for moving your sidebar to the end, it should be a matter of hooking an action that fires late enough that all the sidebars are registered. ‘sidebar_admin_setup’ should be late enough, but fires more often than is really needed. In you action function, save the values of the sidebar you wish to move from $wp_registered_sidebars, then unset that particular key, then assign it again from the saved values. This takes it out of whatever position it was in and places it at the bottom of the array.

    Sorry I can’t be more definitive, but this at least gives you a place to start.

    Thread Starter 9ete

    (@hawkeye126)

    Thanksamundo for the feedback bcworks, i will try this today and post back with results.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add widget to Admin widget area by default’ is closed to new replies.