Skip to main content
2 of 2
Also edited title; deleted 128 characters in body
user avatar
user avatar

Set Desired Permalinks

A new (awesome) theme project I came across this week that is heavily focused on HTML5/CSS3 functionality has it's own 'bootstrap' script to create some boilerplate content, incorporate permalink settings, set a relative root for the site install, etc. These features are called on theme activation. The project is called Roots and the code can be downloaded here ; I take no credit for this code. That said, here's the code to auto-set /year/postname as the permalink structure (and the activation hooks below for global $pagenow are explained here: http://foolswisdom.com/wp-activate-theme-actio/ . ).

<?php
    
    global $pagenow;
    if (is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'])) {
        
                
        // set the permalink structure
        if (get_option('permalink_structure') != '/%year%/%postname%/') { 
            update_option('permalink_structure', '/%year%/%postname%/');
      }
    
        $wp_rewrite->init();
        $wp_rewrite->flush_rules(); 
        
    
    }
    

?>

user4443