I have a subdomain multisite network. I have implemented a system in order to create new subdomains programmatically, just filling a form.
Now I have a need: when a new blog is created, I'd like to set its permalink structure to /postname/.
I've tried these solutions:
How to set permalink structure via functions.php
function set_default_permalink_for_new_blogs($blog_id)
{
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
}
add_action('wpmu_activate_blog', 'set_default_permalink_for_new_blogs');
I've added this snippet in the functions.php of the theme used for the main site, where the system above mentioned is. It simply doesn't work.
How Do I Programmatically Force Custom Permalinks with My Theme?
function change_permalinks() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure('/%postname%/');
$wp_rewrite->flush_rules();
}
add_action('init', 'change_permalinks');
I have some concerns with this snippet: I don't think it could be a good idea to fire the rewrite on every "init" (also someone else expressed doubt about this in comments); in second place, this snippet has to be placed on the default theme of new blogs - but what if I want to change the default theme in future?
Thank you very much for every suggestions,
Marco