Skip to content

Instantly share code, notes, and snippets.

@465media
Created May 25, 2023 14:55
Show Gist options
  • Save 465media/17664b045de75deafcb2b99695d22df9 to your computer and use it in GitHub Desktop.
Save 465media/17664b045de75deafcb2b99695d22df9 to your computer and use it in GitHub Desktop.
Set default "From Email" for Gravity Forms notifications using WordPress domain.
/**
* Set default "From Email" for Gravity Forms notifications using WordPress domain.
*/
function override_gravityforms_from_email( $email, $notification ) {
// Get the WordPress site URL and extract the domain.
$site_url = get_site_url();
$parsed_url = parse_url( $site_url );
$domain = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
if ( isset( $email['from'] ) && $email['from'] === '{admin_email}' ) {
$email['from'] = 'no-reply@' . $domain;
}
return $email;
}
add_filter( 'gform_notification', 'override_gravityforms_from_email', 10, 2 );
@465media
Copy link
Author

@clubdeuce we should be adding something like this to all our builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment