I’ve been having issues on creating new wordpress blogs where I’m setting permalinks via script on theme activation. However, even though they appear to be correct when I check the permalink settings in WP, my new pages are throwing 404 errors.
The only fix I’ve found is that I have to go back to permalink options and click “Save Changes”, even though, according to the display, I’ve made no changes to need to save…
I’m setting permalinks to /%postname%/
Here’s how I’m doing it.
if(get_option('permalink_structure')==""){update_option('permalink_structure', '/%postname%/');}
That script gets run when my theme is activated.
Any ideas why it only partially does the job?
When you set the permalink structure in the WordPress settings panel it calls the
set_permalink_structure
function inwp_includes/rewrite.php
. In addition to setting thepermalink_structure
option this function also reinitialises the WordPress rewrite component and runs thepermalink_structure_changed
action.You should call this function instead of setting the option directly, something like this should work: