Home / Admin / Removing the Header Image From Notification Emails of Specific Forms
Duplicate Snippet

Embed Snippet on Your Site

Removing the Header Image From Notification Emails of Specific Forms

This code snippet hides the header image in notification emails for only a few forms instead of all forms.

<10
Code Preview
php
<?php
/**
 * Remove header image from email notifications for specific form IDs.
 */
add_filter(
    'wpforms_emails_templates_general_set_initial_args',
    'wpforms_remove_header_image_by_form_id',
    10,
    2
);
function wpforms_remove_header_image_by_form_id( $args, $template ) {
    // List the form IDs that should NOT include a header image.
    $forms_without_header = array( 123, 456, 789 ); // Replace with your form IDs.
    // Try to detect the current form ID from multiple contexts.
    $form_id = 0;
    // Check POST data during processing.
    if ( ! empty( $_POST['wpforms']['id'] ) ) {
        $form_id = absint( $_POST['wpforms']['id'] );
    }
    // Fallback to the processor context if available.
    if (
        ! $form_id &&
        function_exists( 'wpforms' ) &&
        ! empty( wpforms()->process->form_data['id'] )
    ) {
        $form_id = absint( wpforms()->process->form_data['id'] );
    }
    // If this form is in our list, remove the header image from email args.
    if ( $form_id && in_array( $form_id, $forms_without_header, true ) ) {
        unset( $args['header']['header_image'] );
    }
    return $args;
}

Comments

Add a Comment