X

Set Permalink Settings from functions.php

Snippets by IsItWP

Permalink settings are available in the WordPress admin settings. Sometimes you may not have the access to WordPress admin and you want to set permalinks settings from functions.php.

Instructions: Add the following code to the functions.php file of your WordPress theme.
The .htaccess mod_rewrite it is still necessary.


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

You may also enjoy flushing permalinks once per hour cron job.

Comments   Leave a Reply

  1. Is this function also working in a multisite install?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!