Education AI

How to Add an AI Tutor to Moodle

Moodle is one of the most widely used open-source learning management systems in the world. Adding a voice AI tutor to it is straightforward — but not through the route most instructors try first. This guide covers the correct method, why the content editor approach fails, and how to test the tutor before students see it.

Updated May 20267 minute read

The most common mistake when adding a custom script to Moodle is pasting it into the course content editor. Moodle's editor — TinyMCE or Atto — strips script tags when the page is saved. It is a security feature, not a bug. The script disappears on save and nothing loads. The correct approach bypasses the content editor entirely and uses a site-level setting that is not filtered.

Prerequisites before you start

Step-by-step: adding the AI tutor to Moodle

Step 1: Get your embed script from Kolsense

Log into your Kolsense dashboard and navigate to the Edu Widget section. Find the widget you have configured for the course, and copy the embed code. It is a small JavaScript snippet, typically one or two lines. It will look something like:

<script src="https://www.kolsense.ai/edu-widget-loader.js" data-key="your-widget-key"></script>

Step 2: Navigate to Additional HTML in Moodle

In Moodle, go to:

  1. Site administration (top-level admin menu)
  2. Appearance
  3. Additional HTML

You will see three text fields: one for code in the head, one at the start of the body, and one at the end of the body.

Step 3: Paste the script into the End of BODY field

Paste your Kolsense embed script into the field labelled "Within HEAD" or "End of BODY". End of BODY is preferred for JavaScript that controls a widget — it ensures the page content loads before the script runs. Click Save changes.

Step 4: Verify it is loading

Navigate to any course page on your Moodle site in a regular browser tab. The AI tutor widget button should appear on the page. If it does not:

Step 5: Test before going live to students

Before students see the widget, test it thoroughly. Ask the kinds of questions your students will actually ask — including questions that are at the edge of the subject scope, questions the tutor should not answer, and conversational or off-topic questions. Confirm that the tutor handles each case the way you expect. If it gives a wrong answer, update the configuration in your Kolsense dashboard and re-test.

Why the content editor does not work

Moodle's content editors have a built-in HTML sanitiser that removes potentially dangerous HTML, including script tags. This is intentional — it prevents malicious code from being embedded in course pages by instructors or students. It also means that any custom JavaScript you paste into a page via the editor will be removed on save. The Additional HTML section in site administration is the designated location for custom scripts — it is accessible only to site administrators and is not filtered.

What students see

Once the widget is live, students see a small button on the course page. When they click it, the browser asks for microphone permission. After granting permission, they can speak directly to the AI tutor. The conversation happens in the browser — no login, no external app. The widget appears on every page of the Moodle site because Additional HTML is site-wide, so students can access the tutor from any course page.

Limitations specific to Moodle

What works well in Moodle

  • Additional HTML method is reliable and not filtered
  • Widget loads on all course pages automatically
  • No plugin installation required
  • Works on any Moodle version that supports Additional HTML
  • Students access via any standard browser

Known limitations

  • Does not work in the Moodle mobile app
  • Site-wide only — no per-course targeting without custom development
  • Requires Moodle site admin access
  • Content editor method does not work — script is stripped on save
  • Allowed domain must match Moodle site domain exactly

For instructors using other platforms

The same Additional HTML or custom code injection approach applies to other LMS platforms, though the location of the setting varies. For WordPress-based platforms like LearnDash or Tutor LMS, the script can typically be added via a custom HTML widget in the theme footer or via a "header and footer scripts" plugin. For Teachable, the Pro plan or above is required — the Starter plan does not allow custom code. For platforms that do not allow any custom code injection, the AI tutor cannot be embedded.

For general guidance on what an AI tutor does and how to configure it, see the AI Tutor for Online Courses guide.

Questions about adding the Kolsense Edu Widget to your Moodle site?

The Kolsense.ai team can help you troubleshoot setup and configure the tutor for your specific course. Reach us at hello@kolsense.ai.

Try Kolsense free

Frequently asked questions

Why doesn't the script tag work when I paste it into the Moodle content editor?
Moodle's content editor (TinyMCE or Atto) strips script tags when you save the page. This is a deliberate security measure. The correct method is to use the Additional HTML section in site administration, which is not filtered. Go to Site administration ? Appearance ? Additional HTML, and paste the script into the "End of BODY" field. This requires Moodle site administrator access.
Will the AI tutor appear on all Moodle courses or just one?
If you add the script via Additional HTML in site administration, it loads on every page of the Moodle site. The Kolsense widget checks whether the domain matches your allowed domain — if it does, the widget appears. To restrict it to one specific course, you would need a Moodle plugin that supports per-course script injection, or a custom theme with that capability. Site-wide deployment via Additional HTML is the simplest and most reliable method.
Does the AI tutor work inside Moodle's mobile app?
No. The Moodle mobile app does not load custom JavaScript added via Additional HTML. The widget works only in a standard web browser — desktop or mobile browser — not in the Moodle app. Students who access Moodle through the app will not see the AI tutor button.
What Moodle permissions do I need to add an AI tutor?
You need Moodle site administrator access. Course editing access alone is not sufficient — the content editor strips script tags as described above. If you do not have site admin access, ask your institution's Moodle administrator to add the code in Additional HTML on your behalf and give them the embed script from your Kolsense dashboard.
How do I test the AI tutor before students see it?
After adding the script, open a course page in a regular browser as a logged-in user. The widget button should appear. Click it, grant microphone permission, and speak a question. Test a variety of question types — ones the tutor should handle well, ones at the edge of the subject scope, and out-of-scope questions — and confirm the tutor behaves as expected in each case. Fix any configuration issues in your Kolsense dashboard before considering it ready for students.