Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to automatically register widgets when a new site is registered with a multi site setup? E.g. inside wpmu_new_blog?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

In your themes functions.php file you can check wether or not it get's installed for the first time on that blog. This can be done by using an option. An option can be set to flag that it's installing.

This option that signals that an install is immanent can be used in a hook of the init jointcut so to flag for automatic widget registration. Widgets can be registerd with wp_set_sidebars_widgets(). After that's done, kill the flag.

Keep in mind that switching themes kills the widgets configuration. So this is for first-time use only.

A full working example on how to register widgets on theme activation can be found in the Semiologic Reloaded Theme. It's available for download, feel free to suit yourself.

share|improve this answer
    
@hakre - Your hyperlink is broken. –  MikeSchinkel Aug 28 '10 at 18:05
    
@hakre - Also, maybe give a working example? If so, you'll answer less questions but they will be more helpful and thus more people will rate your answers highly. Lots of questions answered with only a little direction provided is less useful than fewer questions answered but answered well. When you answer every question with short answers it sometimes causes others to think "Why bother answering, @hakre already has?", at least that's how I sometimes feel. –  MikeSchinkel Aug 28 '10 at 18:12
    
Okay, I see, will take some care on that. –  hakre Aug 28 '10 at 19:51
    
Actually I ended up just modifying the sidebar.php to provide the correct default widgets if no dynamic_sizebar was set. This was good enough for me, but thanks for your more generic solution. –  grm Sep 1 '10 at 8:08
    
Oh okay, it was not clear to me that this would be already fitting for you. –  hakre Sep 1 '10 at 13:52

Much easier. There's the_widget() function already present. Just consult the codex.

share|improve this answer
    
Kaiser: Not really the same thing, is it? The former registers the widget. All you're doing it is calling it. What if I have someone that doesn't want the widget anymore and has no idea how to edit the_widget code? –  user4329 Mar 30 '11 at 17:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.