Define WordPress Permalink Structure Programmically

If you create a lot of WordPress sites or are creating a custom theme, and always want the structure of your permalinks the same, you can add the following code to your functions.php file to have it done automatically.  This code ensures that the permalink structure is created using the category and title.  Modify to meet your needs.

This is especially helpful if you don’t like the default usage of organizing by month and year.

// Force SEO Permalinks
add_action( 'init', function() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%category%/%postname%/' );
} );

How To Remove Space Above Header In WordPressHow To Create A Simple WordPress Theme From ScratchHow To Add Class Depending On Media Screen SizeHow To Disable Post Revisions In WordPressAdd An Edit Link to WordPress Posts