Add a Custom Shortcode Value to LearnDash Notification Emails
Extend [ld_notifications] with your own values, such as a course custom field or a computed count, and list them in the editor instructions box. Verified against the add-on source.

The Notifications add-on (1.6.4) personalises emails with [ld_notifications field="..." show="..."], and the built-in list covers user, course, lesson, topic, quiz, group, essay and assignment data. Sooner or later a site needs something outside that list: the learner's company from a profile field, a course's custom "support contact" field, or a deep link into a dashboard. The add-on exposes two filters for exactly this, one that produces the value and one that documents it in the editor. This snippet guide covers both, plus the pitfalls around escaping and trigger data.
How the shortcode resolves a value
When an email is sent, the add-on stores the trigger data in a global and runs do_shortcode() on the subject and body. Each [ld_notifications] tag reads that data, resolves the requested field and show value, and finally passes the result through the filter learndash_notifications_shortcode_output with three arguments: the computed result, the shortcode attributes, and the data array. The data array always contains user_id and notification_id, and depending on the trigger also course_id, lesson_id, topic_id, quiz_id, question_id, assignment_id and group_id.
One built-in behaviour is worth knowing before writing anything: for field="user", any show value that is not one of the five named ones falls through to get_user_meta( $user_id, $show, true ). So [ld_notifications field="user" show="billing_company"] already prints a user meta key with no code at all. The filter is for everything that is not plain user meta.
Snippet: a course custom field
Suppose each course has a post meta key support_contact. This adds show="support_contact" to the course field:
<?php
add_filter(
'learndash_notifications_shortcode_output',
function ( $result, $atts, $data ) {
if ( 'course' !== $atts['field'] || 'support_contact' !== strtolower( $atts['show'] ) ) {
return $result;
}
if ( empty( $data['course_id'] ) ) {
return '';
}
$contact = get_post_meta( (int) $data['course_id'], 'support_contact', true );
return $contact ? esc_html( $contact ) : '';
},
10,
3
);
Three details matter. Compare the show value in lower case, because the add-on lowercases it before its own switch. Return the original $result untouched for any other field or value, since the filter runs for every tag in the email. And escape what you return: the body is sent as HTML, so a value from user input must be passed through esc_html(), or esc_url() for a link.
Snippet: a value computed from the learner
Values do not have to be stored anywhere. This prints the number of courses the learner has completed, useful in completion emails:
<?php
add_filter(
'learndash_notifications_shortcode_output',
function ( $result, $atts, $data ) {
if ( 'user' !== $atts['field'] || 'completed_course_count' !== strtolower( $atts['show'] ) ) {
return $result;
}
if ( empty( $data['user_id'] ) ) {
return $result;
}
$count = 0;
foreach ( learndash_user_get_enrolled_courses( (int) $data['user_id'] ) as $course_id ) {
if ( learndash_course_completed( (int) $data['user_id'], (int) $course_id ) ) {
$count++;
}
}
return (string) $count;
},
10,
3
);
Because field="user" falls back to user meta, an unknown show value would otherwise print an empty meta lookup; the filter runs after that lookup, so returning your own value replaces it.
Documenting the value in the editor
The notification edit screen shows a "Shortcodes" box whose contents change with the selected trigger. The list is built by grouping shortcodes into user, group, course basic, course advanced, lesson, topic, quiz, essay and assignment sets, then assigning sets to triggers. Both steps are filterable. To add your course value to the course basic group, so that it appears for every course trigger:
<?php
add_filter(
'learndash_notifications_shortcode_instruction_groupings',
function ( $groups ) {
$groups['course_basic']['[ld_notifications field="course" show="support_contact"]'] =
'Display the course support contact.';
return $groups;
}
);
If a value only makes sense for one trigger, use learndash_notifications_shortcodes_instructions instead, which receives the per-trigger array after the groups have been merged, plus the groups themselves, and add the entry under that trigger's key, for example complete_course. The instructions box is documentation only; it does not affect what the shortcode can do.
Where the data array comes up short
Not every trigger provides every ID. The "X days" triggers for login reminders and course expiry set course_ids, a list, rather than a single course, and the built-in course shortcode only supports title and URL for them; your filter should check for course_id and return an empty string when it is absent. Quiz triggers supply quiz_id and course_id, and the quiz result categories live under quiz_result. The triggers guide lists what each one passes.
Using the value in the subject
The notification title becomes the email subject and is also run through do_shortcode(), so a custom value works there too: a subject such as "Your [ld_notifications field="course" show="title"] results" is common, and a custom value like a cohort name reads naturally. Keep subject values plain text, since HTML in a subject is shown literally by mail clients, and return an empty string rather than a placeholder when the data is missing, so that a subject never reads "Your results" with a visible gap. Subjects are also trimmed by the add-on, so a value that resolves to nothing at the end of the line leaves no stray space.
Testing without spamming learners
Create a notification for a trigger you can fire on demand, such as "User completes a lesson", set the recipient to Admin only, and complete a lesson with a test account. The add-on's Logs tab records each send. Once the value is right, switch the recipient back. If the output filter seems to be ignored, check that the shortcode in the body has no typo in the show value and that no caching plugin is serving a stale page where the email is composed, which cannot happen for emails but is a common false lead when testing with page-rendered shortcodes.
When to get help
A single value is a quarter-hour task. Pulling data from a CRM or e-commerce system into notifications, or building a library of values with their own instructions panel, is development work our LearnDash services team does regularly; a LearnDash developer can also review existing notification code against the hooks reference after an add-on update.
Frequently asked questions
Can I print user meta without any code?
Yes. Any show value on the user field that is not username, email, display_name, first_name or last_name is read as a user meta key.
Does the output filter run for delayed emails?
Yes. Delayed emails store the trigger data in the queue and restore it before shortcodes run, so the same filter produces the value later.
Can I add a whole new field name instead of a show value?
Yes. The filter receives the raw attributes, so field="company" can be handled the same way; the built-in code simply produces an empty result for unknown fields before your filter runs.
Is HTML allowed in the returned value?
Yes. Emails are sent as HTML, so a link or bold text in the returned string renders. Escape any user-supplied parts.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
