Created
April 21, 2022 20:32
-
-
Save dietcheese/3da849caf791be65b682cc384cfbeba8 to your computer and use it in GitHub Desktop.
Elementor: display post conditionally based upon whether it has a featured image
This file contains 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
add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) { | |
class Page_Template_Condition extends ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base { | |
public static function get_type() { | |
return 'singular'; | |
} | |
public static function get_priority() { | |
return 30; | |
} | |
public function get_name() { | |
return 'has_featured_image'; | |
} | |
public function get_label() { | |
return __( 'Has Featured Image' ); | |
} | |
public function check( $args ) { | |
return has_post_thumbnail(); | |
} | |
} | |
$conditions_manager->get_condition( 'singular' )->register_sub_condition( new Page_Template_Condition() ); | |
}, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This creates a condition to Elementor that lets you display a template based upon whether a page has a featured image or not.