Removing the custom content when the merge tag is empty
If you added a Custom Content field to your View and its content depends on a Merge Tag (relative to an entry's field), you probably would like to not show anything in case that entry's field is empty.
To enable this logic, you would need to adapt and paste the following code into your theme's functions.php file:
add_filter( 'gravityview/fields/custom/content_before', 'my_gv_custom_content_before', 10, 2 ); /** * Removes the custom content field's content in case a certain entry field is empty * Replace the MY_FIELD_ID by the field id (check it on the Gravity Forms form definition) * * @param string $content Custom Content field content * @param \GV\Template_Context $context * @return string */ function my_gv_custom_content_before( $content, $context = null ) { $id = 'MY_FIELD_ID'; if( empty( $context->entry["{$id}"] ) ) { return ''; } return $content; }
Read here how to add these code samples to your website: Where to put code samples.