Add a “Children of Page” Condition in Elementor Theme Builder

Elementor PHP July 24, 2026

Quick answer: Elementor Pro’s Theme Builder has no built-in “all child pages of X” display condition. This snippet registers a custom Children of Page condition, so you can build one template and have it apply automatically to every child of a parent page — no assigning it page by page.

What it does and when to use it

You have a parent page with a structured set of children — for example Areas We Serve with a city page under it for each location. You want one Elementor template to render on all of those city pages, and to keep applying as you add more. This condition adds exactly that option to Theme Builder’s Display Conditions: pick a parent, and the template shows on its children.

The code

Add it with the Code Snippets or WPCode plugin as a PHP snippet, or in a child theme’s functions.php. It runs only when Elementor Pro is active, so it will not error if Pro is ever disabled.

<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) {

    if ( ! class_exists( '\Elementor\Pro\Modules\ThemeBuilder\Conditions\Condition_Base' ) ) {
        return;
    }

    $singular_condition = $conditions_manager->get_condition( 'singular' );

    if ( ! $singular_condition || ! method_exists( $singular_condition, 'register_sub_condition' ) ) {
        return;
    }

    class Techup_Children_Of_Page_Condition extends \Elementor\Pro\Modules\ThemeBuilder\Conditions\Condition_Base {

        public static function get_type() {
            return 'singular';
        }

        public function get_name() {
            return 'children_of_page';
        }

        public function get_label() {
            return esc_html__( 'Children of Page', 'textdomain' );
        }

        public function get_group() {
            return 'page';
        }

        public function get_all_label() {
            return esc_html__( 'All Child Pages', 'textdomain' );
        }

        public function check( $args ) {
            if ( ! is_page() ) {
                return false;
            }

            $current_post_id = get_queried_object_id();
            if ( ! $current_post_id ) {
                return false;
            }

            $current_parent_id  = wp_get_post_parent_id( $current_post_id );
            $selected_parent_id = 0;

            if ( ! empty( $args['parent_page_id'] ) ) {
                $selected_parent_id = absint( $args['parent_page_id'] );
            } elseif ( ! empty( $args['id'] ) ) {
                $selected_parent_id = absint( $args['id'] );
            }

            if ( ! $selected_parent_id ) {
                return false;
            }

            return (int) $current_parent_id === (int) $selected_parent_id;
        }

        public function get_control_value() {
            $parent_page_id = $this->get_settings( 'parent_page_id' );
            return $parent_page_id ? get_the_title( $parent_page_id ) : '';
        }

        protected function register_controls() {
            $this->start_controls_section(
                'section_parent_page',
                [ 'label' => esc_html__( 'Parent Page', 'textdomain' ) ]
            );

            $this->add_control(
                'parent_page_id',
                [
                    'label'       => esc_html__( 'Select Parent Page', 'textdomain' ),
                    'type'        => \Elementor\Controls_Manager::SELECT2,
                    'label_block' => true,
                    'options'     => $this->get_pages_options(),
                ]
            );

            $this->end_controls_section();
        }

        private function get_pages_options() {
            $pages   = get_pages( [ 'sort_column' => 'post_title', 'sort_order' => 'ASC' ] );
            $options = [];

            if ( $pages ) {
                foreach ( $pages as $page ) {
                    $options[ $page->ID ] = $page->post_title . ' (#' . $page->ID . ')';
                }
            }

            return $options;
        }
    }

    $singular_condition->register_sub_condition( new Techup_Children_Of_Page_Condition() );

}, 20 );
Test this on staging first. It hooks into Elementor Pro’s conditions system, which is powerful but version-sensitive. It is written defensively — it checks the Pro classes exist before running — but as with any Theme Builder change, confirm it on a staging copy before production.

How to use it once the code is active

  1. Edit or create your Elementor Single template.
  2. Open Display Conditions and choose Include → Pages → Children of Page.
  3. Select the parent page (e.g. Areas We Serve) and publish.

The template now renders on every direct child of that parent, including ones you add later.

How to verify

Visit a child page on the front end — it should use the template. Visit the parent, or an unrelated page, and it should not. If the condition does not appear in Theme Builder, confirm Elementor Pro is active and the snippet saved without a PHP error.

How to undo it

Remove the snippet. Any template that used the condition simply falls back to whatever other display conditions it has (or none). No content is affected.