Browse: Home / Snippets /

Display custom message when ld_course_list shortcode has no results

Contents


Snippet #

/**
 * Example usage for ld_course_list filter. Display a custom message when the shortcode returns no results
 */
add_filter(
    'ld_course_list',
    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 = "<strong>No Courses found</strong>";
		}
        // Always return $output.
        return $output;
    },
    10,
    3
);