开发者

Wordpress FORCE UPDATE of permalink settings

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_struc开发者_Python百科ture', '/%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 in wp_includes/rewrite.php. In addition to setting the permalink_structure option this function also reinitialises the WordPress rewrite component and runs the permalink_structure_changed action.

You should call this function instead of setting the option directly, something like this should work:

if (get_option('permalink_structure') == '') {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜