By default it’s possible only using responsive settings, but this way content stays in page source, which is probably not what you need. Here’s the code to solve, just add to functions.php of your child theme


/**
 * Class Elementor_Disable_Section
 */
class Elementor_Disable_Section {
	public function __construct() {
		// Add hooks only if elementor is loaded
		add_action( 'elementor/init', [ $this, 'add_hooks' ] );
	}
	public function add_hooks() {
		// Add our custom control section to Section panel
		add_action( 'elementor/element/section/section_typo/after_section_end', [ $this, 'add_section_controls' ], 10, 2 );
		// Filter if the section was set as disabled
		add_filter( 'elementor/frontend/section/should_render', [ $this, 'should_render' ], 10, 2 );
	}
	/**
	 * should_render
	 *
	 * This is the magic method that actually disables the section
	 * render if it was set as disabled.
	 *
	 * @param bool $should_render
	 * @param object $section
	 * @return void
	 */
	public function should_render( $should_render, $section ) {
		$is_disabled = $section->get_settings( 'is_disabled' );
		if ( ! empty( $is_disabled ) && 'yes' === $is_disabled ) {
			return false;
		}
		return $should_render;
	}
	/**
	 * add_section_controls
	 *
	 * Used to add our "Disable" control to section panel
	 *
	 * @param object $section
	 * @param array $args
	 * @return void
	 */
	public function add_section_controls( $section, $args ) {
		$section->start_controls_section(
			'section_disable',
			[
				'label' => 'Disable Section',
				'tab' => \Elementor\Controls_Manager::TAB_ADVANCED,
			]
		);
		$section->add_control(
			'is_disabled',
			[
				'label' => 'Disable',
				'type' => \Elementor\Controls_Manager::SWITCHER,
			]
		);
		$section->end_controls_section();
	}
};
new Elementor_Disable_Section();

Leave a Reply

Your email address will not be published. Required fields are marked *