我的add_rewrite_rule不起作用的原因有什么原因吗?

发布于 2025-02-01 00:46:01 字数 482 浏览 1 评论 0原文

我正在尝试将重写规则添加到我的WordPress站点中,以“>主题文件编辑器>主题函数”。它似乎无法正常工作。

这看起来正确吗?

function my_custom_rewrite_function() {
    add_rewrite_tag(
        '%id%',
        '([^/]+)'
    );
    add_rewrite_rule('^register/([^/]+)/?', 'index.php?pagename=register&id=$matches[1]', 'top');
    flush_rewrite_rules(); // I have this here for testing so I don't have to manually do it
}
add_action('init', 'my_custom_rewrite_function', 10, 0);

有什么我做错了吗?

I'm trying to add a rewrite rule to my Wordpress site in the "Appearance > Theme File Editor > Theme Functions". It doesn't appear to be working.

Does this look correct?

function my_custom_rewrite_function() {
    add_rewrite_tag(
        '%id%',
        '([^/]+)'
    );
    add_rewrite_rule('^register/([^/]+)/?', 'index.php?pagename=register&id=$matches[1]', 'top');
    flush_rewrite_rules(); // I have this here for testing so I don't have to manually do it
}
add_action('init', 'my_custom_rewrite_function', 10, 0);

Is there anything I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文