Created
August 6, 2025 16:18
-
-
Save bdeleasa/f3b553a70fdf5fef7a55b2681607e5bb to your computer and use it in GitHub Desktop.
A small mu-plugin for Wordpress that adds a display condition in Elementor for page templates.
This file contains hidden or 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 | |
| /** | |
| * @file mu-plugins/elementor-ds.php | |
| * | |
| * A small mu-plugin for Wordpress that adds a display condition in Elementor for page templates. | |
| * | |
| * Why this isn't an option already...I do not know. :) | |
| * | |
| * Thanks to the article below for the code! | |
| * | |
| * @see https://wpjunction.net/elementor-theme-builder-custom-display-condition/ | |
| * | |
| * @package elementor-ds | |
| * @since 1.0.0 | |
| */ | |
| 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 ) { | |
| /** | |
| * Variable-length argument list. | |
| * | |
| * This parameter allows passing a dynamic number of arguments | |
| * to a function or method. Each argument passed is accessible | |
| * as an individual element within this parameter. | |
| * | |
| * @var mixed ...$args Variable-length argument list of mixed types. | |
| */ | |
| 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