Snippet: Add Custom HTML to the LearnDash Focus Mode Header
Every action hook in the ld30 Focus Mode masthead, what sits around each one, and snippets that add a help link beside the logo, a notice next to the progress bar and a custom item in the user menu.

Focus Mode replaces your theme's header with LearnDash's own masthead on lesson, topic and quiz pages, so anything you normally put in the site header, such as a support link or a notice bar, disappears while learners are studying. Editing focus/masthead.php in a child theme works but leaves you maintaining a copy of a template that changes between releases. The masthead in LearnDash 4.18.0.1 fires fourteen action hooks, each with the course ID and user ID, which is enough to put HTML almost anywhere in the bar without touching the template. This snippet maps them and shows three common additions.
The masthead structure
The header is a div.ld-focus-header containing, in order: the mobile navigation trigger, the brand logo in div.ld-brand-logo, the course progress module for logged-in users, the Mark Complete or navigation area, and the user menu in div.ld-user-menu with the welcome text, avatar and a dropdown of menu items. The hooks fire at these points, all with ( $course_id, $user_id ):
| Hook | Fires |
|---|---|
learndash-focus-header-before | Before the header opens |
learndash-focus-header-mobile-nav-before | Before the mobile menu trigger |
learndash-focus-header-logo-before / -logo-after | Around the logo block |
learndash-focus-header-nav-before / -nav-after | Around the Mark Complete and step navigation, after the progress bar |
learndash-focus-header-user-menu-before | Before the user menu block |
learndash-focus-header-avatar-before / -avatar-after | Around the avatar |
learndash-focus-header-user-dropdown-before / -user-dropdown-after | Inside the dropdown, around the menu items |
learndash-focus-header-usermenu-after | After the user menu block |
The template that opens and closes the header, focus/index.php, adds learndash-focus-masthead-before and learndash-focus-masthead-after around the whole bar, which is where a notice bar above the header goes.
Snippet 1: a help link beside the logo
<?php
add_action(
'learndash-focus-header-logo-after',
function ( $course_id, $user_id ) {
$attributes = array(
'class' => 'wwc-focus-help',
'href' => esc_url( home_url( '/help/' ) ),
);
$attribute_html = '';
foreach ( $attributes as $name => $value ) {
$attribute_html .= sprintf( ' %1$s="%2$s"', $name, esc_attr( $value ) );
}
printf(
'<a%1$s>%2$s</a>',
$attribute_html, // Each value escaped above.
esc_html__( 'Need help?', 'wwc' )
);
},
10,
2
);
Building the attributes as an array keeps the escaping visible and makes it easy to add a target or rel later. Style the link with a small rule in your child theme so it sits inline with the logo:
.ld-focus .ld-focus-header .wwc-focus-help {
margin-left: 1rem;
font-size: 0.875rem;
align-self: center;
}
The header is a flex row, so a new element placed between existing blocks simply takes its turn in the row; align-self: center lines it up with the logo.
Snippet 2: a notice next to the progress bar
Because the hooks receive the course ID, the content can be course-specific. This prints the course's end date, when one is set, before the Mark Complete button:
<?php
add_action(
'learndash-focus-header-nav-before',
function ( $course_id, $user_id ) {
$end = learndash_get_setting( $course_id, 'course_end_date' );
if ( empty( $end ) ) {
return;
}
printf(
'<span class="wwc-focus-deadline">%1$s %2$s</span>',
esc_html__( 'Course closes', 'wwc' ),
esc_html( learndash_adjust_date_time_display( (int) $end, get_option( 'date_format' ) ) )
);
},
10,
2
);
learndash_get_setting() reads the stored course settings, and the end date is kept as a timestamp when set on the course's Settings tab. Keep the text short; the bar has limited width on tablets, and the mobile layout stacks it.
Snippet 3: a custom item in the user dropdown
LearnDash offers a filter for the dropdown items and a menu location, which our Focus Mode guide covers. For HTML that is not a link, such as a short status line, the dropdown hooks are the alternative:
<?php
add_action(
'learndash-focus-header-user-dropdown-before',
function ( $course_id, $user_id ) {
if ( empty( $user_id ) ) {
return;
}
$status = learndash_course_status( $course_id, $user_id );
printf(
'<span class="wwc-focus-status">%1$s: %2$s</span>',
esc_html__( 'Course status', 'wwc' ),
esc_html( $status )
);
},
10,
2
);
Without the third argument, learndash_course_status() returns the translated label, Not Started, In Progress or Completed, ready for display.
Escaping and what not to print
Everything you echo should pass through esc_html(), esc_attr() or esc_url() as above, including text from settings. Avoid printing block-level elements such as div inside the dropdown, which expects inline items, and avoid scripts; enqueue JavaScript properly instead. Do not rely on get_the_ID() in these callbacks for the course, because the current post is the lesson or quiz; the hook already hands you the course ID.
Ordering several additions
When more than one plugin or snippet hooks the same action, WordPress runs them in priority order, lowest number first, and in registration order within a priority. If your help link should sit after a third-party addition at the same hook, register yours at priority 20. For a block that must be first inside the header, learndash-focus-header-mobile-nav-before runs before anything else prints, and because it fires regardless of login state it is also the safest hook for content every visitor should see. Keep each callback to one job so that reordering means changing a number rather than rewriting markup.
Mobile layout
Below the tablet breakpoint the masthead hides the course navigation behind the menu trigger and shrinks the user menu to the avatar. Additions placed with the logo hooks remain visible, so keep them short or hide them with a media query if space is tight. Additions placed with the nav hooks disappear into the collapsed state along with the navigation, which is usually acceptable for secondary information such as a deadline but not for a support link. Test with the browser's device toolbar at 360 and 768 pixels wide, since those are the widths where the header reflows.
Checking your theme has not removed the hooks
If nothing appears, the theme or a plugin may override focus/masthead.php. LearnDash's template loader checks the child theme and theme for a copy before using its own, as explained in the template system guide; open the override and search for the hook name. Keep your snippets in a child theme functions file or mu-plugin per our update-safe customisation guide.
Testing
- Enable Focus Mode under LearnDash LMS > Settings > General > Design & Content Elements and open a lesson as a logged-in learner.
- Confirm each addition appears where the table says, then resize to tablet and phone widths.
- Log out and view the lesson of an open course; the user menu and progress bar are absent, so only the logo hook output should remain.
When to get help
A link or a line of text is a short task. A redesigned masthead with a course switcher, a timer or support chat is a template override project, which our LearnDash services team handles along with the UI and UX design behind it, and a LearnDash developer can convert an existing override back into hooks so the next update does not break it.
Frequently asked questions
Which hook adds content next to the Focus Mode logo?
learndash-focus-header-logo-after, fired in the ld30 masthead with the course ID and user ID immediately after the logo block.
Can I add a bar above the Focus Mode header?
Yes. learndash-focus-masthead-before in the focus index template fires before the header opens.
Do the hooks fire for logged-out visitors?
The logo and navigation hooks do. The user menu, avatar and dropdown hooks sit inside a logged-in check and do not fire for visitors.
How do I add a link to the user dropdown?
Use the Focus Mode menu location or the dropdown items filter for plain links. Use the dropdown hooks for HTML that is not a menu link.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
