Using shortcodes inside Gravity Forms notifications
When sending a notification, you may want to have a different email subject line based on the value of a field. In that case, you can use [gvlogic]. Unfortunately, Gravity Forms only processes shortcodes inside a notification's Message field (the email body). It does not process shortcodes inside other fields, such as the Subject.
To process shortcodes inside other notification fields, we will use Gravity Forms’ gform_notification filter. Here's an example of processing shortcodes inside the To, Subject, and From Name fields:
ℹ️ Only run shortcodes that you know contain safe output! Using a shortcode in these fields has the potential to break the Notifications functionality.
/**
* @param array $notification
*/
add_filter( 'gform_notification', function( $notification ) {
$notification['to'] = do_shortcode( $notification['to'] );
$notification['subject'] = do_shortcode( $notification['subject'] );
$notification['fromName'] = do_shortcode( $notification['fromName'] );
return $notification;
} );
Now, you can use shortcodes inside your subject line like this:
[gvlogic if="{Industry:3}" is="Automobiles"]🚘 Drive in![else]🚴 Bike in![/gvlogic]