How to set WordPress permalink structure via functions.php

How to set WordPress permalink structure via functions.php

How to set WordPress permalink structure via functions.php

By default, WordPress allows you to change or modify the permalink structure via dashboard  settings page (Settings >> Permalinks). However, you can also do the same thing using functions.php file. To do this we are going to use the set_permalink_structure() method of global $wp_rewrite.

See Also : Set Minimum Order Amount in WooCommerce

To change the WordPress permalink structure via functions.php file, use the following code.

//Set WordPress permalink structure via functions.php
Function ccw_set_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
}
add_action( 'init', 'ccw_set_permalinks' );

Visit the following link to know more about the structure tags in WordPress:

http://codex.wordpress.org/Using_Permalinks#Structure_Tags

2 Comments

Leave a Comment.