Hook: LearnDash Focus Mode Head

Updated 3 years ago
by Dave Warfel

You might need to add some additional code to the <head> section of LearnDash focus mode pages. Maybe it’s some JavaScript that you need to run, some additional CSS file you want to add for focus mode only, or a font you need to initialize with a <script> tag.

Whatever the case may be, LearnDash has a hook you can use. LearnDash hooks allow you to add content to various areas in LearnDash templates without editing the template itself.

do_action( ‘learndash-focus-head’ );

This action hook runs just before the closing </head> tag on all focus mode pages.

Here’s an example of how to add JavaScript via a <script> tag:

function ldxc_focus_mode_head() {
	echo "<script type='text/javascript'>
		// Custom JavaScript goes here
	</script>";
}
add_action( 'learndash-focus-head', 'ldxc_focus_mode_head', 10, 1 );

Or add a link to a CSS file:

function ldxc_focus_mode_head() {
	echo "<link rel='stylesheet' href='https://YOURSITE.com/link/to/custom-styles.css'>";
}
add_action( 'learndash-focus-head', 'ldxc_focus_mode_head', 10, 1 );

All CSS code should either be placed in a child theme’s main CSS file (typically style.css), or the Additional CSS area of the WordPress Customizer.

How to Add CSS to Your Site

Forum Rules

Be Kind & Patient

We’re here to learn and/or help each other. Please don’t be mean, rude, or condescending. Treat all members the way you should be treating dogs and your elders—with the utmost love & respect.

External Links

✅ Other websites that add value, help solve problems & contribute to the discussion. ❌ Affiliate links are prohibited. (Site owners may use affiliate links to help support the site.)

Promotion

✅ You may promote your own products/services if they are relevant to an existing discussion. You must disclose your relationship with the product(s).
❌ You may not create new posts simply to promote your products.

Non-LearnDash Topics

❌ General (free) Forum: Only LearnDash-specific topics are allowed.
✅ Premium Forums: You are allowed to post other questions tangentially related to LearnDash. Please use the appropriately named forum. If it doesn’t exist, use the “LearnDash Integrations” forum.

Our Right to Remove

We reserve the right to remove any content, at any time, for any reason. We can also merge one post with another. We will exercise caution when removing content and always try to provide an explanation.