Skip to content

Instantly share code, notes, and snippets.

@tomslominski
Created November 13, 2023 19:33
Show Gist options
  • Save tomslominski/ce716bd9178a534e19fe7d33de7eb345 to your computer and use it in GitHub Desktop.
Save tomslominski/ce716bd9178a534e19fe7d33de7eb345 to your computer and use it in GitHub Desktop.
Custom Elementor condition
<?php
add_action( 'elementor/theme/register_conditions', function( \ElementorPro\Modules\ThemeBuilder\Classes\Conditions_Manager $manager ) {
require get_theme_file_path( 'gutenberg-page-condition.php' );
$manager->get_condition( 'singular' )->register_sub_condition( new Gutenberg_Page() );
} );
<?php
if( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Gutenberg_Page extends ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
public static function get_type() {
return 'singular';
}
public static function get_priority() {
return 20;
}
public function get_name() {
return 'gutenberg_page';
}
public function get_label() {
return esc_html__( 'Gutenberg Page', 'domain' );
}
public function check( $args ) {
if( !is_singular() ) {
return false;
}
return !Elementor\Plugin::instance()->documents->get( get_the_ID() )->is_built_with_elementor();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment