Reputation: 23
I am trying to setup some default widgets areas and add to them some default widgets when my theme is activated.
On a fresh WordPress install I got some widgets in the first sidebar
( search, recent posts, archives, meta area),
I am using unregister_widget()
to remove those widgets,
now I cannot find a way to add widgets to those sidebars via functions.php.
Could you help me, please?
Thanks for now.
Upvotes: 1
Views: 1278
Reputation: 2850
unregister_widget
is going to completely remove the widget from the system making it unavailable for use. What you need to be doing is removing/adding widgets to the sidebar, not unregistering them. There is a good post on the WordPress specific forum: https://wordpress.stackexchange.com/questions/26557/programmatically-add-widgets-to-sidebars
The basic idea is to manipulate the widgets array stored in the options table.
$widgets = get_option( 'sidebars_widgets' );
var_dump($widgets);
If you look at that var_dump
it should be pretty obvious what is happening. The tricky part is that all the widgets have numeric suffixes so that multiples can be used.
Upvotes: 1