Would you like to hide field labels for non-input fields like Content, HTML, Page Break, and Section Divider fields in entry views and email notifications? In this tutorial, we’ll show you how to use a simple code snippet with the wpforms_html_field_name
filter to hide field labels in entry views and email notifications.
Adding the Code Snippet
To hide field labels, you’ll need to add a custom code snippet to your site. If you need help adding custom code, please see our tutorial on adding code snippets.
The code snippet shown below hides the label for Content fields in the print view of a single entry:
/*
* Hide Field Labels in Entry Views and Notifications.
*
* @link https://wpforms.com/developers/how-to-hide-field-labels-in-entry-views-and-notifications
*
*/
function wpf_hide_field_label( $field_label, $field, $form_data, $context ) {
if ( $context !== 'single-print' ) {
return $field_label;
}
$field_type = ! empty( $field['type'] ) ? $field['type'] : '';
if ( $field_type === 'content' ) {
$field_label = ''; // Leave this empty to hide the label value
}
return $field_label;
}
add_filter( 'wpforms_html_field_name', 'wpf_hide_field_label', 10, 4 );
Customizing the Snippet
You can modify this snippet to suit your specific needs:
1. To apply the changes to a different area, change the $context
value. Available options are:
single-print
: Single entry print viewsingle-entry
: Single entry viewemail-html
: Email notifications
2. To target different field types, modify the field_type
value. Available options are:
content
html
divider
pagebreak
And that’s it! You’ve now successfully hid the labels for non-input fields while showing the content.