search ]

Set Permalink Structure from functions.php

I do not see a reason you would want to do this, but you can set the WordPress permalink structure via code. To do this, add the following code to your theme’s functions.php file and change the permalink structure as needed:

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

Note that mod_rewrite must be active on the server in this case as well.

More on WordPress permalink structure in this post: Choosing the best permalink structure for SEO.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo