Blog

  • Why Elementor Disobeys is_admin()

    I was surprised to learn that when editing a page using Elementor‘s page builder, is_admin() returns false. The reason for this is that Elementor is loading the page in an <iframe> element as if it were being viewed on the front-end.

    Use code like this to detect when posts or pages are being edited in Elementor. Code like this is useful to me because sometimes I add a meta refresh element to automatically start a download, and I don’t want the redirect and download to happen while editing the page.

    //don't do anything if we're editing in Elementor
    if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
        return;
    }

    Here is other code that relies on a URL querystring parameter.

    //don't do anything if we're editing post 1112 in Elementor
    if( isset( $_GET['elementor-preview'] ) && '1112' == $_GET['elementor-preview'] ) {
        return;
    }
  • Using register_setting() and the REST API

    Here is a comment I just requested be added to the bottom of the register_setting() page.

    If you plan to use your setting in the REST API, use both the rest_api_init and admin_init hooks when calling register_setting() instead of just admin_init. The show_in_rest argument is ineffective when hooked into admin_init alone.

    Corey Salzano

    Someday, when my comment is approved, you’ll be able to see it on this page and save an hour or two of debugging time. If you can see my comment on this page, please let me know.