My parent page:
Virtual pages are:
I use shortcode in parent page that gets id number from URL then show the result.
Now all above pages show 404 errors. Is it possible to use the parent page for showing all pages with links containing example/id/
I used this but it does not work:
function edit_the_permalink($url){
if(strpos($url, get_site_url().'/id/') !== false){
$url = get_site_url().'/id/';
}
return $url;
}
add_filter('the_permalink', 'edit_the_permalink');
My parent page: http://example/id
Virtual pages are:
- http://example/id/1563
- http://example/id/john/5896
- http://example/id/jack-miami/3054
I use shortcode in parent page that gets id number from URL then show the result.
Now all above pages show 404 errors. Is it possible to use the parent page for showing all pages with links containing example/id/
I used this but it does not work:
function edit_the_permalink($url){
if(strpos($url, get_site_url().'/id/') !== false){
$url = get_site_url().'/id/';
}
return $url;
}
add_filter('the_permalink', 'edit_the_permalink');
Share
Improve this question
edited Feb 4, 2016 at 10:19
Sven
3,6841 gold badge35 silver badges48 bronze badges
asked Feb 4, 2016 at 9:13
user2511140user2511140
1515 bronze badges
1 Answer
Reset to default 0add_filter('the_permalink')
, is the wrong tool for the job, it gets you the full permalink for the current post or a specific post ID.
It seems like the proper approach would be to use a rewrite rule:
add_filter('query_vars', function($vars){
$vars[] = 'id';
return $vars;
});
add_rewrite_rule('id\/([\w\-]+)\/?', 'index.php?id=$matches[1]', 'top');
CAVEAT: I haven't tried this, and id
might be a reserved name in the rewrite rule.
But, this is the general idea for getting virtual subpages from a real parent page.