Sometimes you need Elementor to behave a little smarter — like showing a template only under certain circumstances. In this guide, you'll create a custom condition in Elementor Pro using PHP. No plugins, just clean code that integrates directly with Elementor’s Theme Builder system.
Step 1: Understand What a Condition Is
Conditions in Elementor let you control where templates appear across your site — for example, showing a header only on specific pages or displaying a section only for logged-in users. In this example, we'll create a condition that displays a template only if the current post has comments.
Step 2: Open Your functions.php File
Head into your active theme folder — usually under `wp-content/themes/your-theme-name` — and open the `functions.php` file. We'll be adding our custom condition directly here. You can also place it inside a small custom plugin if you prefer to keep your theme clean.
Step 3: Create the Custom Condition
Add the following code to your `functions.php` file. This snippet defines a new condition called “Has Commented” that checks if the current post contains comments.
1add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) {
2
3 class Elementor_Has_Commented_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
4
5 public static function get_type() {
6 return 'singular';
7 }
8
9 public function get_name() {
10 return 'has_commented';
11 }
12
13 public function get_label() {
14 return 'Has Commented';
15 }
16
17 public function check( $args ) {
18 return have_comments();
19 }
20 }
21
22 $conditions_manager->get_condition_instance( 'general' )->register_sub_condition( new Elementor_Has_Commented_Condition() );
23
24 });Here’s a quick breakdown of what’s happening in the code:
- We hook into `elementor/theme/register_conditions` to add our custom condition when Elementor initializes.
- We create a class that extends `Condition_Base`, which is the foundation for all Elementor Theme Builder conditions.
- `get_type()` returns the type of condition. We use `'singular'` because our condition applies to individual posts.
- `get_name()` sets the internal condition name, while `get_label()` defines the name shown in the Elementor editor.
- `check()` defines the actual logic. Here we simply return `true` if the current post has comments.
Step 4: Test the Condition
Once you’ve added the code, head into the Elementor editor and open any template. Click **Conditions**, and you should now see your new “Has Commented” option in the dropdown list. Select it, save the template, and it will only display on posts that have comments.
Full Working Example
1add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) {
2
3 class Elementor_Has_Commented_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
4
5 public static function get_type() {
6 return 'singular';
7 }
8
9 public function get_name() {
10 return 'has_commented';
11 }
12
13 public function get_label() {
14 return 'Has Commented';
15 }
16
17 public function check( $args ) {
18 return have_comments();
19 }
20 }
21
22 $conditions_manager->get_condition_instance( 'general' )->register_sub_condition( new Elementor_Has_Commented_Condition() );
23
24 });Useful Links
Elementor Theme Builder Conditions API documentation:
Elementor Developer Hooks reference:
That’s all you need to build your own Elementor condition. From here, you can create conditions based on user roles, custom fields, or any other logic you want — giving you full control over how your Elementor templates behave.

I’m an experienced SEO professional with over a decade of helping over 100 businesses rank higher online, especially local businesses, e-commerce stores and SaaS. As the co-founder of LPagery, I specialize in practical, proven strategies for regular SEO and Local SEO success.