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');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742346143a4426581.html
评论列表(0条)