When a new blog is created in a WP Multisite instance I want to be able to set the default theme and configuration options
-
create 2 menus (main and secondary) and associate them with the 2 slots provided by the theme
-
set various theme options as defined on the theme option page
What’s the best way to go about achieving this?
-
which hook should i use – I’m going to use this: (‘WP_DEFAULT_THEME’, ‘theme-folder-name’ in wp-config.php to set the default theme – unless this prevents a needed hook from firing.
-
easiest way to programatically create menus and associate them with existing theme menu ‘slots’
The best hook I can find is
wpmu_new_blog
(line 1086,wp-includes/ms-functions.php
,wpmu_create_blog()
) – it passes 6 arguments like so;$meta
is an array of initial site options, not to be confused with the options generated bypopulate_options()
.Programatically creating nav menus may prove to be a little tricky, as there is no ‘API’ as such – they’re a mix of posts, post meta and
nav_menu
terms, coupled with a few available functions such asis_nav_menu_item()
andwp_setup_nav_menu_item()
.My best advice would be to check out
wp-admin/nav-menus.php
, as this is where all the core code lies for creating menus.Using
WP_DEFAULT_THEME
should be fine, and is probably the best approach too.This is a little late, but I had to figure out the other part of this question on my own and thought I would share.
To create a default menu and place it into a theme location, you will need a pre-existing location in the theme, and you will need to ensure any pages you link in your menu are also created already.
In your theme’s function.php, register any menu locations. I registered two:
Next, you will need to create your menus on site creation. I didn’t use a hook for this, but instead called
wpmu_create_blog
manually, but you could hook intowpmu_new_blog
if you preferred.Lastly, you’ll need to add items to the menus. Repeat this code for each item in each menu.
Hope this helps! Here are some external references for you:
This works for me!