Custom URL rewrite breaks post editor
-
I have the following setup:
* custom post typecustom-post
* and a rewrite rule to link `/custom-post/demo’ to a special page:function rewrite_rules() { $postName = "custom-post"; $postId = 123; add_rewrite_rule( $postName.'/?([^/]*)/', // also tried: '(?!.*elementor)'.$postName.'/?([^/]*)/?$', 'index.php?page_id=' . $postId.'&pid=$matches[1]&ptype='.$postName, 'top' ); } add_action('init', 'rewrite_rules');
Those parts work fine but I have trouble opening the custom post Elementor editor. When it opens
https://localhost/~test/wp-admin/post.php?post=1786&action=elementor
by clicking on “edit with Elementor” it will try to openhttps://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603
. It fails with the error that it can’t findthe_content
.
I’m using a custom theme and the theme pages do havethe_content()
included.Is there a way to prevent the Elementor editor to follow that
add_rewrite_rule
? I’ve tried to use'(?!.*elementor)'.$postName.'/?([^/]*)/?$'
as a rule and in my regex tests it will only match the frondend URLhttps://localhost/~test/custom-post/demo/ https://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603
and not the elementor-preview URL but the editor still tries to follow the rule. If I remove the rule the Elementor editor will open correctly. So I would like to use that rule only for the frontend and make the backend ignore it.
- The topic ‘Custom URL rewrite breaks post editor’ is closed to new replies.