Created
September 16, 2025 08:12
-
-
Save manishsongirkar/b39cb9f77e39dcce0915008253c77d52 to your computer and use it in GitHub Desktop.
Checks if the current page is being viewed in the Elementor editor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Checks if the current page is being viewed in the Elementor editor. | |
| * | |
| * This function determines if the user is currently in the Elementor | |
| * page builder's edit or preview mode. It also returns true if | |
| * the user is in the WordPress admin area, as Elementor's editor | |
| * is a part of the admin interface. | |
| * | |
| * @return bool True if in the Elementor editor or WordPress admin, false otherwise. | |
| */ | |
| function is_elementor_editor() { | |
| if ( | |
| is_admin() || ( | |
| class_exists( '\Elementor\Plugin' ) && | |
| ( | |
| \Elementor\Plugin::$instance->preview->is_preview_mode() | |
| || \Elementor\Plugin::$instance->editor->is_edit_mode() | |
| ) | |
| ) | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| # Usage | |
| # Within function do not execute any frontend related changes in the editor. | |
| if ( is_elementor_editor() ) { | |
| return; | |
| } |
Author
manishsongirkar
commented
Sep 16, 2025
Author
/**
* Remove Elementor Post Styles.
*
* @return void
*/
function dequeue_elementor_post_styles() {
if ( is_elementor_editor() ) {
return;
}
$disable_elementor = true;
$active_kit_handle = '';
$active_kit_id = get_option( 'elementor_active_kit' );
if ( $active_kit_id ) {
$active_kit_handle = sprintf( 'elementor-post-%d', $active_kit_id );
}
$post_css_handle = sprintf( 'elementor-post-%d', get_the_ID() );
/**
* Apply a filter to alter the state of `disable_elementor`
*
* This filter allows other plugins or themes to change the value of `$disable_elementor`,
* which can be used to enqueue/dequeue the Elementor Post Styles on certain Posts or conditions.
*
* @param bool $disable_elementor The current state of whether Elementor Post Styles Enqueue is disabled or not.
* @return bool Modified value of `$disable_elementor`.
*/
$disable_elementor = apply_filters( 'global_blocks_dequeue_elementor_post_styles', $disable_elementor, get_the_ID() );
if ( ! is_admin() && $disable_elementor ) {
if ( $active_kit_handle && wp_style_is( $active_kit_handle, 'enqueued' ) ) {
wp_dequeue_style( $active_kit_handle );
}
if ( wp_style_is( $post_css_handle, 'enqueued' ) ) {
wp_dequeue_style( $post_css_handle );
}
}
}
add_action( 'elementor/css-file/post/enqueue', 'dequeue_elementor_post_styles' );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment