theme development - Default Permalink Type to Postname

I need my theme to default Permalink Type to Postname. Upon activation, my theme is executing the following code:chang

I need my theme to default Permalink Type to Postname. Upon activation, my theme is executing the following code:

   //change permalinks to /%postname%/
    global $wp_rewrite; 

    //Write the rule
    $wp_rewrite->set_permalink_structure('/%postname%/'); 

    //Flush the rules and tell it to write htaccess or IIS
    $wp_rewrite->flush_rules();

As part of the process of activating permalinks, WordPress updates web server rewrite rules. This works fine on a *nix web server, updating the rewrite rules in .htaccess, but it doesn’t create the rewrite rules for IIS.

Ok, maybe to do with permissions on the Windows machine?

Here’s the anomaly, on Windows, when the permalink is updated from the permalink settings page, the rewrite rules are correctly set in the IIS web.config.

MY QUESTION IS, with Windows IIS, how come the settings page updates the permalink type without a problem, yet the above code doesn’t (but does on *nix)?

I will NOT write a script to manually update the rewrite rules. It should be upto the WordPress API to do this.

I need my theme to default Permalink Type to Postname. Upon activation, my theme is executing the following code:

   //change permalinks to /%postname%/
    global $wp_rewrite; 

    //Write the rule
    $wp_rewrite->set_permalink_structure('/%postname%/'); 

    //Flush the rules and tell it to write htaccess or IIS
    $wp_rewrite->flush_rules();

As part of the process of activating permalinks, WordPress updates web server rewrite rules. This works fine on a *nix web server, updating the rewrite rules in .htaccess, but it doesn’t create the rewrite rules for IIS.

Ok, maybe to do with permissions on the Windows machine?

Here’s the anomaly, on Windows, when the permalink is updated from the permalink settings page, the rewrite rules are correctly set in the IIS web.config.

MY QUESTION IS, with Windows IIS, how come the settings page updates the permalink type without a problem, yet the above code doesn’t (but does on *nix)?

I will NOT write a script to manually update the rewrite rules. It should be upto the WordPress API to do this.

Share Improve this question asked Mar 27, 2019 at 16:06 dewddewd 17911 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

I don't think it's a good approach. Themes shouldn't change any settings and definitely not settings like permalink structure.

If I've set my permalinks structure to given one, then I had my reasons to do it. Such change have many effects. If you change the permalink structure you cause many SEO problems. But also - the site may stop working at all (for example if the server doesn't support permalinks at all or if it doesn't have access rights to .htaccess file).

So... The real question is not how to force WP to recalculate the permalinks, but who to avoid such operation at all.

If you really need a permalink structure to be set to given one, then you can politely ask user to change it using admin notice.

But to be honest, I really doubt that a theme should require such changes. It should work with any permalink structure.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745653485a4638404.html

相关推荐

  • theme development - Default Permalink Type to Postname

    I need my theme to default Permalink Type to Postname. Upon activation, my theme is executing the following code:chang

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信