LMS & eLearning

Building a Custom Course Grid Card Design

A walkthrough for adding your own card to LearnDash Course Grid 2.x: registering it with the cards filter, writing the template with the variables provided, adding data, shipping a stylesheet and using it.

Building a Custom Course Grid Card Design

The five stock cards cover the common layouts, but a brand usually wants its own: a level badge, a price with the old price struck through, an instructor photo in a specific place, a hover state. Course Grid 2 lets you add a card without touching the existing ones, so the default cards keep working on other pages and the custom one is selectable by name.

This tutorial builds a custom LearnDash course grid card called Brand from start to finish in version 2.0.9: registration, the template, extra data, the stylesheet, and the editor. It assumes a child theme or a small site plugin for the code, and some familiarity with WordPress template PHP.

Step 1: register the card

Cards live in a registry you extend through the learndash_course_grid_cards filter. Each entry has a label, the skins it supports and the elements it renders, which the editor uses to decide which toggles to show. Add this to your site plugin:

add_filter(
	'learndash_course_grid_cards',
	function ( $cards ) {
		$cards['brand'] = array(
			'label'    => __( 'Brand', 'your-textdomain' ),
			'skins'    => array( 'grid', 'masonry' ),
			'elements' => array( 'thumbnail', 'ribbon', 'content', 'title', 'description', 'post_meta', 'button' ),
		);

		return $cards;
	}
);

The key, brand, is the value you will pass as card="brand", and it is also the folder name the plugin will look for.

Step 2: create the template

The plugin resolves a card named brand to cards/brand/layout.php under learndash/course-grid/ in your theme, with the plugin's own folder as the fallback, which does not exist for a custom card. So the template must be in the theme:

wp-content/themes/your-child-theme/learndash/course-grid/cards/brand/layout.php

Start from a copy of templates/cards/grid-2/layout.php in the plugin, because it already handles the thumbnail, video, ribbon, title, description and button with the right conditions and escaping, then reshape it. A trimmed version that adds a level badge and a struck-through old price:

<div class="item brand">
	<article id="post-<?php echo esc_attr( $post->ID ); ?>" <?php post_class( 'post', $post->ID ); ?>>
		<?php if ( $atts['thumbnail'] == true ) : ?>
			<div class="thumbnail">
				<?php if ( $atts['ribbon'] == true && ! empty( $ribbon_text ) ) : ?>
					<div class="<?php echo esc_attr( $ribbon_class ); ?>"><?php echo esc_html( $ribbon_text ); ?></div>
				<?php endif; ?>
				<a href="<?php echo esc_url( $button_link ); ?>">
					<?php echo get_the_post_thumbnail( $post->ID, $atts['thumbnail_size'] ); ?>
				</a>
			</div>
		<?php endif; ?>
		<div class="content">
			<?php if ( ! empty( $level ) ) : ?>
				<span class="level"><?php echo esc_html( $level ); ?></span>
			<?php endif; ?>
			<?php if ( $atts['title'] == true ) : ?>
				<h3 class="entry-title"><a href="<?php echo esc_url( $button_link ); ?>"><?php echo esc_html( $title ); ?></a></h3>
			<?php endif; ?>
			<?php if ( $atts['description'] == true && ! empty( $description ) ) : ?>
				<div class="description"><?php echo wp_kses_post( $description ); ?></div>
			<?php endif; ?>
			<div class="price-row">
				<?php if ( ! empty( $old_price ) ) : ?>
					<del><?php echo esc_html( $old_price ); ?></del>
				<?php endif; ?>
				<span class="price"><?php echo esc_html( $price_text ); ?></span>
			</div>
			<?php if ( $atts['button'] == true ) : ?>
				<a class="button" href="<?php echo esc_url( $button_link ); ?>"><?php echo esc_html( $button_text ); ?></a>
			<?php endif; ?>
		</div>
	</article>
</div>

Keep the outer item element and the article; the skin stylesheet and equal-height rule rely on them. Everything printed is escaped. Two variables here, $level and $old_price, are not provided by the plugin, which brings us to step 3.

Step 3: add data through the attributes filter

Before a card template runs, the plugin builds the post's attributes array and passes it through learndash_course_grid_template_post_attributes with the post object. Anything you add to the array becomes a local variable in the template:

add_filter(
	'learndash_course_grid_template_post_attributes',
	function ( $post_atts, $post ) {
		$post_atts['level']     = get_post_meta( $post->ID, '_brand_level', true );
		$post_atts['old_price'] = get_post_meta( $post->ID, '_brand_old_price', true );

		return $post_atts;
	},
	10,
	2
);

The meta keys are yours to define; a small meta box or a custom fields plugin can expose them to editors. Computing values here rather than in the template keeps the template simple and makes the data available to any card. The variables the plugin already provides are listed in our guide to overriding course grid templates.

Step 4: ship a stylesheet

Place style.css next to the template, at learndash/course-grid/cards/brand/style.css. When a grid using the card is on the page, the plugin enqueues that file automatically with the handle learndash-course-grid-card-brand, after the general and skin stylesheets. The grid wrapper adds the skin class, and each card has the item and brand classes, so rules like .learndash-course-grid .grid > .item.brand .level are specific enough without an id. If the card needs JavaScript, a script.js in the same folder is enqueued the same way. External libraries can be declared in the registration array under script_dependencies or style_dependencies with a url and version, as the masonry skin does.

The grid's colour and font attributes still apply, because they are written against the card's title, description, ribbon, icon and button classes; reuse the stock class names (entry-title, description, ribbon, button) where the element plays the same role so editors keep those controls.

Step 5: use it

[learndash_course_grid id="catalog" card="brand" skin="grid" columns="3" grid_height_equal="true"]

The block editor does not expose the card attribute in 2.0.9, so with the block the custom card cannot be selected unless you add card to the editor's field list with learndash_course_grid_editor_fields. With that filter in place the editor shows a card control populated from the registry, including Brand. Alternatively, make Brand the default for every grid with the defaults filter:

add_filter(
	'learndash_course_grid_default_shortcode_attributes',
	function ( $defaults ) {
		$defaults['card'] = 'brand';
		return $defaults;
	}
);

Testing checklist

  • Logged out and enrolled views: ribbon, button text and link differ.
  • Courses without a featured image: the stock cards print a placeholder; decide what yours does.
  • Long titles and descriptions with equal heights on.
  • Load More: cards appended over AJAX use the same template, so they should match. If they do not, the template depends on something only available on the initial page load.
  • Masonry, if you listed it as a supported skin.
  • Mobile widths, since the skin collapses columns but your card's internal layout is your own.

Going further

A card registered this way can be shipped in a plugin for reuse across sites, as long as the template lives in each theme or you register the card's template through your own loader. Cards that pull data from other systems, such as ratings from a review plugin through the learndash_course_grid_reviews filter or instructor profiles from a membership plugin, follow the same pattern: compute in the attributes filter, print in the template. The remaining hooks are in our Course Grid hooks reference. When the catalog is the main sales page, design and build of the card is worth doing properly; our LearnDash services team pairs a designer with a LearnDash developer for exactly this, and the price, progress and student count guide covers the data most card designs ask for.

Frequently asked questions

Can a custom card work with the list skin?

Yes. List list in its skins array and write the layout for a horizontal card. Each registration can support one or more skins.

Where should the registration code live?

In a site plugin or the child theme's functions file. The template and stylesheet must be in the theme because of the template lookup rules.

Why does the editor not show my card?

The block hides the card control by default. Add card through the learndash_course_grid_editor_fields filter, or use the shortcode.

Can I reuse the stock card's CSS?

Copy the relevant rules from the plugin's card stylesheet into yours and adjust the card class. Enqueueing the stock card's stylesheet as a dependency also works if the markup stays similar.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Free consultation

Need help with LearnDash?

Tell us what you are working on. A developer who does this every week reads your message and replies within one business day with next steps and a free quote.

  • Free consultation and quote
  • NDA on request
  • You own the source code
  • Reply within one business day

Tell us about your project

Add budget and timeline optional, helps us quote faster

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.