Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from JoelEadeDesign/functions.php
Created June 12, 2024 19:17
Show Gist options
  • Save dexit/7bca8d276192a8b7b9f9fa44741081d6 to your computer and use it in GitHub Desktop.
Save dexit/7bca8d276192a8b7b9f9fa44741081d6 to your computer and use it in GitHub Desktop.
Elementor Display Conditions for Page Templates
<?php
/**
* Elementor Conditions based on Page Template
*
* @return void
*/
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 'page_template';
}
public function get_label() {
return __( 'Page Template' );
}
public function check( $args ) {
return isset( $args['id'] ) && is_page_template( $args['id'] );
}
protected function _register_controls() {
$this->add_control(
'page_template',
[
'section' => 'settings',
'label' => __( 'Page Template' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => array_flip( get_page_templates() ),
]
);
}
}
$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