Rewrite URL with add_rewrite_rule only for frontend
-
I want to add a rewrite rule to render a custom post type (/custom-post/child1) to a special page:
function rewrite_rules() { $postName = "custom-post"; $postId = 123; add_rewrite_rule( $postName.'/?([^/]*)/', 'index.php?page_id=' . $postId.'&pid=$matches[1]&ptype='.$postName, 'top' ); } add_action('init', 'rewrite_rules');
This works fine BUT it breaks editing the post with Elementor in the backend.
Can I change the rule so that it will only work for the frontend? I’ve tried it with !is_admin() around it but then it won’t work in the frontend anymore.
The rewrite rule should only apply for “/custom-post/child1” to “fixed page” while viewing the post in the frontend not while I’m editing pages in the backend.
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Rewrite URL with add_rewrite_rule only for frontend’ is closed to new replies.