The gform_preview_header action is triggered when the header of the form preview page loads, allowing further actions to be done.
Usage
add_action('gform_preview_header', 'my_custom_function', 10, 1);
Parameters
$form_id
(int): The ID of the current form being previewed.
More information
See Gravity Forms Docs: gform_preview_header
This action hook was added in Gravity Forms 2.4.19.
Source Code: This action hook is located in preview.php
.
Examples
Add custom CSS to form preview header
This example adds custom CSS to the form preview header.
function my_custom_function($form_id) { echo '<style> body { background-color: #f9f9f9; } .gform_wrapper { border: 1px solid #ccc; } </style>'; } add_action('gform_preview_header', 'my_custom_function', 10, 1);
Display a custom message above the form
This example displays a custom message above the form in the form preview.
function my_custom_function($form_id) { echo '<div class="custom-message">This is a form preview. Some features might not work as expected.</div>'; } add_action('gform_preview_header', 'my_custom_function', 10, 1);
Load a custom JavaScript file
This example loads a custom JavaScript file in the form preview header.
function my_custom_function($form_id) { echo '<script src="/path/to/your/custom.js"></script>'; } add_action('gform_preview_header', 'my_custom_function', 10, 1);
Add custom meta tags to form preview header
This example adds custom meta tags to the form preview header.
function my_custom_function($form_id) { echo '<meta name="viewport" content="width=device-width, initial-scale=1">'; } add_action('gform_preview_header', 'my_custom_function', 10, 1);
Conditionally load custom styles for specific forms
This example loads custom styles for specific forms based on their form ID.
function my_custom_function($form_id) { if ($form_id == 5) { echo '<style> body { background-color: #f9f9f9; } .gform_wrapper { border: 1px solid #ccc; } </style>'; } } add_action('gform_preview_header', 'my_custom_function', 10, 1);