2

I am trying to set permalink structure on theme activation. The following function included in function.php of theme.

// Executes function on theme activation
function myactivationfunction() {

    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%category%/%postname%/' );
    // register taxonomies/post types here
    flush_rewrite_rules();

}
add_action("after_switch_theme", "myactivationfunction", 10 ,  2);

This code works correctly but value not writing into .htaccess or .htaccess not creating. How can i write .htaccess file dynamically?

Any help would be greatly appreciated.

Thanks

7
  • flush_rewrite_rules() restores the .htaccess rules automatically. These are the same for almost all rules, so don’t expect to see any changes. Look at the last modified time to see if the file was updated.
    – fuxia
    Oct 12, 2013 at 9:09
  • If i delete .htaccess file before activating theme and .htaccess not creating after activation of theme.
    – hariprasad
    Oct 12, 2013 at 9:13
  • the .htaccess is creating when i access the permalink options under settings of wordpress dashboard.
    – hariprasad
    Oct 12, 2013 at 11:07
  • 2
    why do you want to change .htaccess? for your permalink structure setting? If so, it's no need to deal with .htaccess. rewrite rules of permalink structures are stored in database. you just need to make sure any kind of url will be pointing to index.php in htaccess.
    – Jesse
    Oct 13, 2013 at 0:16
  • @Jesse Thanks for your reply. Probably there should be a 404 error while moving to inner pages of the site if the permalink is '/%category%/%postname%/'. To avoid this need to update .htaccess.
    – hariprasad
    Oct 15, 2013 at 7:09

0

Browse other questions tagged or ask your own question.