How do I check whether a WordPress page is currently viewed “as a regular page” or “in the Elementor visual editor”?
I’ve written a plugin that redirects users when a specific shortcode if present on a page. It works like a charm, but unfortunately the Elementor visual editor dies when a page redirects the client. I want the plugin to redirect only when the Elementor editor isn’t active.
My first idea was to check if the URL contains action=elementor
, as it does when Elementor editor is active, and do something like this:
global $wp;
if ( strpos(home_url( $wp->request ), 'action=elementor') !== false ) {
// don't redirect
}
but this does not work, as home_url( $wp->request )
only returns the permalink of the page but not the actually called URL.
2
Answers
Okay nevermind... This does the trick:
You can use this