Thursday, September 21, 2023

Why are you getting an error in httpdocs/wp-content/plugins/code-snippets/php/snippet-ops.php when trying to preview a page in elementor (SOLVED)

Well, how the hell should I know... :)
What I can tell you is why I was getting such an error and hopefully it might help you too.

In my case the page included a snippet that was registering a short code, this shortcode was expecting some parameters on the URL or POST, but since they would not be passed into the page when opened for viewing in elementor the shortcode was broken.

But I was not all to blame (I think...),
I did have code that checked:

	if(is_admin()) {
            return '<div id="app">SOME PLACEHOLDER CONTENT FOR ADMIN VIEW<</div>';
    }

I don't know when it broke but ir seems that it has something to do with elementor loading the content in an iframe where is_admin() returns false.
after cheching it turns out that the following is better and works also in the iframe....

	if(is_admin() || $_GET['elementor-preview']) {
            return '<div id="app">SOME PLACEHOLDER CONTENT FOR ADMIN VIEW</div>';
    }

Did this help you? leave me a comment....

 
Clicky Web Analytics