Created
November 5, 2024 22:51
-
-
Save chrisegg/9efa645cf313003c0f67c76c3c500b1c to your computer and use it in GitHub Desktop.
Using a CSS class 'hide-from-entries' you can prevent fields from showing in the entry details page. Add the class to the fields Custom CSS Class area.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms // Remove fields from entry details page | |
* https://gravityranger.com/ | |
* | |
* Using a CSS class 'hide-from-entries' you can prevent fields from showing in the entry | |
* details page. Add the class to the fields Custom CSS Class area. | |
* | |
* Step-by-Step Tutorial: https://gravityranger.com/gravity-forms-hide-from-entries/ | |
* | |
* | |
*/ | |
add_filter('gform_field_content', function ($field_content, $field, $value) { | |
// Check if the field is a section field and has the custom class 'hide-from-entries' | |
if ($field->type === 'section' && strpos($field->cssClass, 'hide-from-entries') !== false) { | |
// Check if we are on the entry details screen | |
if ($field->is_entry_detail()) { | |
// Remove content from entry details screen | |
return ''; | |
} elseif ($field->is_entry_detail_edit()) { | |
// Only on the entry edit screen, output as a hidden field | |
$value = esc_attr($value); | |
$name = 'input_' . esc_attr($field->id); | |
return "<input type='hidden' name='{$name}' value='{$value}'>"; | |
} | |
} | |
// Return the default field content if no conditions are met | |
return $field_content; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment