admin管理员组文章数量:1334799
I'm using a shortcode on some of my pages and need to add a gender to the page urls.
For example, if the page slug is "/ninjas/", I need to be able to use urls like "/ninjas/female/" and "/ninjas/male/" for the page.
Default behavior is that I get a 404, but I would just like to get the page as normal.
Is that possible somehow?
Thanks!
I'm using a shortcode on some of my pages and need to add a gender to the page urls.
For example, if the page slug is "/ninjas/", I need to be able to use urls like "/ninjas/female/" and "/ninjas/male/" for the page.
Default behavior is that I get a 404, but I would just like to get the page as normal.
Is that possible somehow?
Thanks!
Share Improve this question asked Jun 15, 2020 at 9:22 MadsMads 11 bronze badge 3- what is it you want to do with the extra part? do you need to show different pages depending on the gender? If so how where do you want Wordpress to get ninjas/female or ninjas/male from? – mozboz Commented Jun 15, 2020 at 9:59
- are you saying you have these pages workiing but they have a 404 status code? What have you tried so far? Note that because it's a shortcode you can't know in advance which pages to extend via rewrite rules – Tom J Nowell ♦ Commented Jun 15, 2020 at 10:04
- The page /ninjas/ exists, but there's no /female/ page with parent = "/ninjas/". That's why I get the 404. I'll use the extra part in the shortcode (which I code myself). Have a database table with the pages that must be able to be extended, so I guess what I need is a rewrite rule hint or two :) – Mads Commented Jun 15, 2020 at 10:13
1 Answer
Reset to default 0This code fixes the problem:
function gender_endpoints() {
add_rewrite_endpoint('female', EP_PAGES);
add_rewrite_endpoint('male', EP_PAGES);
}
add_action('init', 'gender_endpoints');
本文标签: permalinksExtending page urls without getting a 404
版权声明:本文标题:permalinks - Extending page urls without getting a 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742346143a2457559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论