gpt4 book ai didi

php - wordpress自定义重写规则

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:11 29 4
gpt4 key购买 nike

我正在尝试让自定义重写规则起作用,但目前它不起作用。也许有人可以提供帮助?

我想要的说出 url 看起来像这样:domain/the-brand/xyz

domain/?pagename=brand-2&brand=xyz 是工作 url...

我已经在 functions.php 中添加了一个自定义标签:

function custom_rewrite_tag() {
add_rewrite_tag('%brand%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

和一个自定义规则,但似乎有一个错误:

function custom_rewrite_rule() {
add_rewrite_rule('/the-brand/([^/]*)' , 'index.php?pagename=brand-2&brand=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

最佳答案

看起来您做对了,您只想刷新永久链接 as noted here

Note that these rules are usually called inside the init hook. Furthermore, permalinks will need to be refreshed (you can do this from your admin under Settings > Permalinks) before the rewrite changes will take effect. Requires one-time use of flush_rules() to take effect. See also Flushing Rewrite on Activation.

关于php - wordpress自定义重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936873/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com