How to remove parent slugs from child pages permalinks?
-
I remove them all right, but when I actually try to go to a page, there is a 404 error.
The code I use ( variation of https://wordpress.stackexchange.com/questions/182006/removing-parent-pages-from-permalink#answer-313280 ):
function my_pages_permalink( $link, $post_id) { $slugname = get_post_field( 'post_name', $post_id, 'display' ); $slugname = $slugname."/"; $link = untrailingslashit( home_url($slugname) ) . '.html'; return $link; } add_filter( 'page_link', 'my_pages_permalink', 10, 3 );
What else should be done? Directives in .htaccess do not help. Some add_rewrite_rule has to be used? I have tried stuff like that:
function my_pages_permalink_rewrite() { add_rewrite_rule('^(.+?)/(.+?)$', 'index.php?pagename=$matches[2]', 'top'); } add_action('init', 'my_pages_permalink_rewrite');
but to no avail.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to remove parent slugs from child pages permalinks?’ is closed to new replies.