Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Created December 19, 2019 00:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeel-raza/dfe5954182c73dc889b91b22c0f2669a to your computer and use it in GitHub Desktop.
Save adeel-raza/dfe5954182c73dc889b91b22c0f2669a to your computer and use it in GitHub Desktop.
Add new tag to lessons/topics/quizzes inside LeanrDash course table which are updated within 30 days
<?php
add_action( 'learndash-lesson-row-title-after', 'learndash_add_tag_to_new_lessons', 10, 3);
function learndash_add_tag_to_new_lessons( $lesson_id, $course_id, $user_id ) {
$lesson = get_post( $lesson_id );
if ( strtotime( $lesson->post_modified ) > strtotime( '-30 days' ) ) {
echo "<span class='ld-content-new-tag'>" . __( "(New)", 'sfwd-lms' ) . "</span>";
}
}
add_action( 'learndash-topic-row-title-after', 'learndash_add_tag_to_new_topics', 10, 3);
function learndash_add_tag_to_new_topics( $topic_id, $course_id, $user_id ) {
$topic = get_post( $topic_id );
if ( strtotime( $topic->post_modified ) > strtotime( '-30 days' ) ) {
echo "<span class='ld-content-new-tag'>" . __( "(New)", 'sfwd-lms' ) . "</span>";
}
}
add_action( 'learndash-quiz-row-title-after', 'learndash_add_tag_to_new_quizzes', 10, 3);
function learndash_add_tag_to_new_quizzes( $quiz_id, $course_id, $user_id ) {
$quiz = get_post( $quiz_id );
if ( strtotime( $quiz->post_modified ) > strtotime( '-30 days' ) ) {
echo "<span class='ld-content-new-tag'>" . __( "(New)", 'sfwd-lms' ) . "</span>";
}
}
@adeel-raza
Copy link
Author

Place this snippet in your theme's functions.php file and a New tag will be displayed next to lessons/topcis/quizzes inside the LeanrDash course content table on the course page.
Please note that a CSS class is added to all the new tags .ld-content-new-tag so that you can easily design the look and feel by adding CSS rules in your theme's custom CSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment