Skip to main content
Also edited title; deleted 128 characters in body
Source Link
user4443
user4443

Set Desired Permalinks Setting/Menus

I realize this thread is a little dated by now but I did not see anyone answer the permalink question or follow-up on the menus items. 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: foolswisdom.com/wp-activate-theme-actio/ http://foolswisdom.com/wp-activate-theme-actio/ . ). Some of this code is also concerned with creating two menus and setting pages to those menus...the menu response above mine is from 6+ months ago and I was not sure if progress was made there either.

<?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(); 
        
        
        // automatically create menus and set their locations
        // add all pages to the Primary Navigation
        $primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation'));
        $utility_nav_id = wp_create_nav_menu('Utility Navigation', array('slug' => 'utility_navigation'));
        set_theme_mod('nav_menu_locations', array(
            'primary_navigation' => $primary_nav_id, 
            'utility_navigation' => $utility_nav_id
        )); 
        
        $primary_nav = wp_get_nav_menu_object('Primary Navigation');
        $primary_nav_term_id = (int) $primary_nav->term_id; 
        $pages = get_pages();
        foreach($pages as $page) {
            $item = array(
                'menu-item-object-id' => $page->ID,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type',
                'menu-item-status' => 'publish'
            );
            wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
        }
    
    }
    

Set Desired Permalinks Setting/Menus

I realize this thread is a little dated by now but I did not see anyone answer the permalink question or follow-up on the menus items. 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: foolswisdom.com/wp-activate-theme-actio/ . ). Some of this code is also concerned with creating two menus and setting pages to those menus...the menu response above mine is from 6+ months ago and I was not sure if progress was made there either.

<?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(); 
        
        
        // automatically create menus and set their locations
        // add all pages to the Primary Navigation
        $primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation'));
        $utility_nav_id = wp_create_nav_menu('Utility Navigation', array('slug' => 'utility_navigation'));
        set_theme_mod('nav_menu_locations', array(
            'primary_navigation' => $primary_nav_id, 
            'utility_navigation' => $utility_nav_id
        )); 
        
        $primary_nav = wp_get_nav_menu_object('Primary Navigation');
        $primary_nav_term_id = (int) $primary_nav->term_id; 
        $pages = get_pages();
        foreach($pages as $page) {
            $item = array(
                'menu-item-object-id' => $page->ID,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type',
                'menu-item-status' => 'publish'
            );
            wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
        }
    
    }
    

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(); 
        
    
    }
    
Source Link
user4443
user4443

Set Desired Permalinks Setting/Menus

I realize this thread is a little dated by now but I did not see anyone answer the permalink question or follow-up on the menus items. 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: foolswisdom.com/wp-activate-theme-actio/ . ). Some of this code is also concerned with creating two menus and setting pages to those menus...the menu response above mine is from 6+ months ago and I was not sure if progress was made there either.

<?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(); 
        
        
        // automatically create menus and set their locations
        // add all pages to the Primary Navigation
        $primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation'));
        $utility_nav_id = wp_create_nav_menu('Utility Navigation', array('slug' => 'utility_navigation'));
        set_theme_mod('nav_menu_locations', array(
            'primary_navigation' => $primary_nav_id, 
            'utility_navigation' => $utility_nav_id
        )); 
        
        $primary_nav = wp_get_nav_menu_object('Primary Navigation');
        $primary_nav_term_id = (int) $primary_nav->term_id; 
        $pages = get_pages();
        foreach($pages as $page) {
            $item = array(
                'menu-item-object-id' => $page->ID,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type',
                'menu-item-status' => 'publish'
            );
            wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
        }
    
    }
    

?>