Created
April 23, 2024 01:58
-
-
Save JoelEadeDesign/3cc27fcc366af51bceae29d398c63db3 to your computer and use it in GitHub Desktop.
Elementor Display Conditions for Page Templates
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
<?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