Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elementor - Remove markup for hidden element - Remove the markup for an element that is set to hidden on desktop, table and mobile. https://www.damiencarbery.com/2021/06/elementor-remove-markup-of-hidden-element/
<?php
/*
Plugin Name: Elementor - Remove markup for hidden element
Description: Remove the markup for an element that is set to hidden on desktop, table and mobile.
Plugin URI: https://www.damiencarbery.com/2021/06/elementor-remove-markup-of-hidden-element/
Version: 0.1
Author: Damien Carbery
*/
defined( 'ABSPATH' ) || exit;
// Do not render on front end a widget that is hidden on all three device types.
// The element is still present and editable in admin area.
// See: https://code.elementor.com/php-hooks/#elementorwidgetrender_content
add_action( 'elementor/widget/render_content', 'dcwd_skip_hidden_elementor_widget', 10, 2 );
function dcwd_skip_hidden_elementor_widget( $content, $widget ) {
if ( is_admin() ) { return $content; } // Do not change element when editing the page/post.
$settings = $widget->get_settings();
if ( isset( $settings[ 'hide_desktop' ] ) && isset( $settings[ 'hide_tablet' ] ) && isset( $settings[ 'hide_mobile' ] ) &&
( 'hidden-desktop' == $settings[ 'hide_desktop' ] ) && ( 'hidden-tablet' == $settings[ 'hide_tablet' ] ) && ( 'hidden-phone' == $settings[ 'hide_mobile' ]) ) {
//error_log( 'Widget to hide: ' . $widget->get_name() );
//error_log( 'Content to skip: ' . $content );
return '';
}
//error_log( 'Widget: ' . $widget->get_name() );
//error_log( 'Content: ' . $content );
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment