ARTICLE AD BOX
I am trying to create a learndash feedback function incorporating notes by learndash.
I've currently gotten to creating the custom button that will appear under each question but I am unable to extract the question text so that i can use it as a basis for feedback. My questions are randomized and im unsure of how to call the question ID without it being changed due to the randomize feature.
I've tried looking at the learndash developer site to find the relevant code but currently struggling as I'm starting out.
/** * LearnDash per-question feedback modal with title only * Shows "Help Improve this Question!" button below each quiz question * Prefills note title with first 5 letters of question */ add_action( 'learndash-quiz-after', 'radtm_feedback_modal_title_only', 10, 3 ); function radtm_feedback_modal_title_only( $quiz_id = 0, $course_id = 0, $user_id = 0 ) { // OPTIONAL: restrict to specific courses $allowed_courses = array( 1 ); if ( ! in_array( intval( $course_id ), $allowed_courses, true ) ) { return; } // Feedback Button echo '<div class="radtm-feedback-wrap" style="margin-top:1.5em;">'; echo '<button id="radtm-feedback-btn" type="button" style="background:#1c6cce;color:#fff;border:none;padding:.7rem 1rem;border-radius:6px;font-weight:600;font-size:16px;cursor:pointer;"> Help Improve this Question! </button>'; echo '</div>'; // Hidden modal container echo '<div id="radtm-feedback-modal" style="display:none;"> <div id="radtm-feedback-overlay" style=" position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);z-index:9998;"> </div> <div id="radtm-feedback-content" style=" position:fixed;top:50%;left:50%;transform:translate(-50%, -50%); background:#fff;z-index:9999;padding:1.5rem;border-radius:8px; max-width:600px;width:90%;box-shadow:0 4px 15px rgba(0,0,0,0.3);"> <button id="radtm-feedback-close" style=" float:right;background:#ccc;color:#222;border:none;padding:0.3rem 0.6rem; border-radius:4px;font-weight:600;cursor:pointer;margin-bottom:1rem;">X</button> <div id="radtm-feedback-note">'; // Insert LearnDash Notes form inline echo do_shortcode('[llms_add_new_note]'); echo ' </div> </div> </div>'; // JS to open modal and prefill title only $js = <<<JS (function(){ var btn = document.getElementById("radtm-feedback-btn"); var modal = document.getElementById("radtm-feedback-modal"); var closeBtn = document.getElementById("radtm-feedback-close"); if(!btn || !modal || !closeBtn) return; btn.addEventListener("click", function(e){ e.preventDefault(); // Detect current visible question var qEl = document.querySelector(".ld-quiz-question.current, .ld-quiz-question[aria-hidden='false']"); if(!qEl) qEl = document.querySelector(".ld-quiz-question"); var questionText = ""; if(qEl){ var qTextEl = qEl.querySelector(".ld-quiz-question-title, .ld-question-text"); if(qTextEl) questionText = qTextEl.textContent.trim(); } // Title is first 5 letters of question var noteTitle = questionText.substring(0,5); // Show modal modal.style.display = "block"; // Prefill title input var titleInput = modal.querySelector("input[name='llms_note_title']"); if(titleInput){ titleInput.value = noteTitle; titleInput.focus(); } }); // Close modal closeBtn.addEventListener("click", function(){ modal.style.display = "none"; }); document.getElementById("radtm-feedback-overlay").addEventListener("click", function(){ modal.style.display = "none"; }); })(); JS; echo '<script type="text/javascript">' . $js . '</script>'; // CSS adjustments echo '<style> #radtm-feedback-btn:hover { background: #155a9c; } @media (prefers-color-scheme: dark) { #radtm-feedback-btn { background:#1c6cce; color:#fff; } #radtm-feedback-content { background:#222; color:#fafafa; } #radtm-feedback-close { background:#444; color:#fff; } } </style>'; }