Skip to content

Instantly share code, notes, and snippets.

@cpaul007
Last active December 21, 2021 16:18
Show Gist options
  • Save cpaul007/482af7f3ac34920cb74ee0a7521255e9 to your computer and use it in GitHub Desktop.
Save cpaul007/482af7f3ac34920cb74ee0a7521255e9 to your computer and use it in GitHub Desktop.
Conditionally hide the Zion element
<?php // do not include this line and enter the bottom code in your theme's functions.php file
/**
* Hiding the element based on the condition
*
* @author Chinmoy Paul
* @version 1.0
*/
class EmptyElement {
public function render_element( $extra_data ) {
echo '';
}
}
function isZionBuilderEditor() {
if( isset( $_SERVER['HTTP_REFERER'] ) && strstr( $_SERVER['HTTP_REFERER'], 'zion_builder_active' ) && ! isset($_GET['preview']) ) {
return true;
}
return false;
}
add_filter( 'zionbuilder/renderer/custom_renderer', 'zu_apply_condition_logic', 10, 2 );
function zu_apply_condition_logic( $null, $element ) {
if( isZionBuilderEditor() )
return $null;
/**
* you will target the specific element via element UID
* or custom ID(you can set it from Advanced Tab)
*/
$elid = $element->options->get_value( '_advanced_options._element_id', $element->get_uid() );
$emptyElement = new EmptyElement();
/**
* apply your own condition logic here and it will not show the element
**/
if ( is_home() && $elid == 'uid124344623235' ) { //* replace 'uid124344623235' with your own element's UID or ID
return $emptyElement;
}
if ( is_page(10) && $elid == 'uid1243446234356' ) { //* replace 'uid1243446234356' with your own element's UID or ID
return $emptyElement;
}
return $null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment