How to set permalink structure via functions.php

You can set the permalink structure by calling on the set_permalink_structure() method of the global $wp_rewrite object.

add_action( 'init', function() {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
} );

Here’s a PHP < 5.3 version of the code in case you’re getting errors.

function reset_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
}
add_action( 'init', 'reset_permalinks' );

Leave a Comment