Description

Fires before a form is displayed on the site’s frontend and inside the HTML form container. It will only fire if the form exists and contains fields.

Parameters

$form_data
(array) Processed form settings/data, prepared to be used later.

Source

wpforms/includes/class-frontend.php

More Information

While wpforms_frontend_output only fires for valid non-empty forms, it executes early on in the output rendering process. However, what you place with this action will be displayed inside the HTML form container.

An alternate action to consider is wpforms_frontend_output_before, as it functions similarly, except it will be outside of the HTML form container.

Examples

In our example code snippet, you’ll see below, we are going to be checking first to see if the form ID is equal to 5. If it is, we’ll echo out a link to download the digital catalog.

Just remember to change the form ID from 5 to match the specific form ID you’re wanting to run your code on. Removing that check would run for all forms.

/**
 * Output something before your form(s).
 * 
 * @link  https://wpforms.com/developers/wpforms_frontend_output/
 *
 * @param array  $form_data Form data and settings.
 */
function wpf_frontend_output_before( $form_data ) {
    
    // Optional, you can limit to specific forms. Below, we restrict output to
    // form #5.
    if ( absint( $form_data['id'] ) !== 5 ) {
        return;
    } 

    // Run code.
 

}
add_action( 'wpforms_frontend_output_before', 'wpf_dev_frontend_output_before', 10, 1 );