Skip to content

Instantly share code, notes, and snippets.

@JeffAspen
Created August 10, 2018 18:34
Show Gist options
  • Save JeffAspen/b33398541bdc44783ed5008b28642429 to your computer and use it in GitHub Desktop.
Save JeffAspen/b33398541bdc44783ed5008b28642429 to your computer and use it in GitHub Desktop.
Elementor - Hide widgets
<?php
// Hide Elementor sections / elements when acf field is empty. Everything is shown when editor is active
// Usage: Add acf__[field_slug] classname into the desired element (for example acf__caption, acf__map-section)
$all_acf_fields = get_fields();
echo '<style>';
foreach($all_acf_fields as $acf_field_slug => $acf_field_value) {
if ($acf_field_value == ''){
echo 'body:not(.elementor-editor-active) .acf__'.$acf_field_slug.' { display: none; }';
}
};
unset($value);
echo '</style>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment