Affiliate Disclosure: We may be compensated if you use our links to make a purchase. We are extremely selective in who we partner with & only recommend products we believe in. Our affiliate relationships do not influence our recommendations.

When using LearnDash course grid parameters to customize the output of the grid, some users or instances might return no results. By default, when the course grid doesn’t show any courses, the area is left blank. But what if you want to display a custom message in place of your grid when no courses are available?

This article will show you how to do that.

Bonus Tip: We’ll even show you how to display a custom Elementor template for a course grid with no results. 🤯

Using a Custom Code Snippet

First, let’s quickly talk about the code we’ll be using to make this happen. It’s PHP code that uses a LearnDash hook.

My preferred way to make changes like this is with the Code Snippets plugin. You could also add this code to the functions.php file of your child theme (if you’re using one), but I find Code Snippets to be easier to manage and less likely to bring your site down if you make a mistake.

  1. Install & activate “Code Snippets” from your WordPress plugins page
  2. Navigate to Snippets > Add New in the left sidebar
  3. Give your snippet a name. Something like “LearnDash Course Grid – No Results Message”
  4. Paste the code snippet into the Code area
  5. Choose the Only run on site front-end option
  6. Click the Save Changes and Activate button

The Code

Here’s the code you’re going to use. It uses a filter for the ld_course_list hook. First, it checks to see if any courses have been found in your course grid query. If it doesn’t find any, it updates the $output parameter to include a custom message.

 * Example usage for ld_course_list filter. Display a custom message when the shortcode returns no results
	function( $output, $atts, $filter ) {
		// If the ld-course-list-items div does not have items/courses to display, use a custom message as output.
		if ( preg_match( '@<div class="ld-course-list-items row">\s+</div>@', $output ) ) {
			$output = "<p>No courses found.</p>";
		// Always return $output.
		return $output;

What you can customize

In the code above, the only part that you should touch is the part following $output =, inside the quotes. This is what will be displayed when no courses are found.

The example above will display, “No courses found.”

This code uses HTML, thus why you see the opening <p> and closing </p> tags. That just stands for “paragraph,” and it ensures your text inside of it will be styled properly.

If you know HTML, feel free to get creative here. Use multiple <div>s, write your own custom CSS, etc.

Use an Elementor Template

If you don’t know HTML but still want to do something creative or more elaborate in this space, you can use an Elementor template.

  1. Create a new Elementor Section and save it in your templates
  2. Go to Templates > Saved Templates
  3. Copy the Elementor Shortcode value

Elementor saved template shortcode

  1. Replace the $output = line above with this, using your unique template ID

$output = apply_shortcodes( '[elementor-template id="2154"]' );

Now when no courses are available in your grid, your custom Elementor template will be used.

Please share in the comments if you create something fun 😀.