Skip to content

Instantly share code, notes, and snippets.

@dietcheese
Created April 21, 2022 20:32
Show Gist options
  • Save dietcheese/3da849caf791be65b682cc384cfbeba8 to your computer and use it in GitHub Desktop.
Save dietcheese/3da849caf791be65b682cc384cfbeba8 to your computer and use it in GitHub Desktop.
Elementor: display post conditionally based upon whether it has a featured image
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 );
@dietcheese
Copy link
Author

This creates a condition to Elementor that lets you display a template based upon whether a page has a featured image or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment