
Dreamforce 2026: What AIforce Changes for Enterprise AI ArchitectureRead More

Building custom plugins is a great way to make Moodle work exactly how we need it to. When we first started customizing Moodle, it seemed complicated, but once we broke it down into steps, it turned out to be quite manageable. In this blog, we’ll walk you through creating your first Moodle plugin with simple, easy-to-follow steps. Let’s get started!
Before we start, make sure you have:
Moodle has different plugin types, each serving a specific purpose. The most common ones are:
For this blog, we'll create a simple block plugin since they're the easiest to start with.
Let's create a simple block that displays a motivational quote to students. First, we need to set up our folder structure.
Inside your new folder, create these files:

Open version.php and add the following lines of code:

This code is used in a Moodle plugin to define important details about the plugin. The first line checks if the file is being accessed properly through Moodle; if not, it stops the script for safety. The next few lines provide information about the plugin, such as its name (block_motivational_quotes), the version number based on the date (May 11, 2025), and the minimum Moodle version it needs to work (April 24, 2023). It also shows that this is version 1.0 of the plugin and that it is stable and ready for use.
Open lang/en/block_motivational_quotes.php and add:

These lines define the text that will be shown to users for different parts of the "Motivational Quotes" block in Moodle. The $string['pluginname'] sets the name of the plugin that users will see. The $string['motivational_quotes'] is usually the title shown on the block itself. The next two lines set permission strings, one allows a user to add the block anywhere (addinstance), and the other allows adding it specifically to their personal dashboard (myaddinstance). These text labels help Moodle display clear options and messages to users when they use or manage the block.
Open db/access.php and add:

This code defines who is allowed to add the "Motivational Quotes" block in Moodle and where they can add it. The first line ensures the file is only run inside Moodle. Then, two permissions (called capabilities) are listed. The first one, block/motivational_quotes:addinstance, lets users like editing teachers and managers add the block to course pages. It also includes a risk warning for things like spam or unsafe content (XSS). The second permission, block/motivational_quotes:myaddinstance, allows any user to add the block to their personal dashboard. Both permissions copy behavior from existing Moodle permissions to make the setup easier and more consistent.
Now for the main plugin file. Open block_motivational_quotes.php and add:

This code creates the main part of the "Motivational Quotes" block in Moodle. It defines a class that extends Moodle's block system. The init() function sets the title of the block using the plugin name. The get_content() function controls what shows up inside the block. It picks a random quote from a list of motivational quotes and displays it. If the content is already set, it just returns it to save time. The applicable_formats() function says this block can be shown on any page, and instance_allow_multiple() allows users to add more than one copy of this block to a page
Now it's time to install your plugin:
After installation:


Once you get the basics working, here are some ways to improve your plugin.
Adding configuration options is pretty straightforward. You'll want to create a settings.php file in your plugin folder. This lets you add a text box where admins can put in their own quotes. Then you just need to update your block to pull these quotes from the settings instead of using the built-in ones.
If you need to store more complex data, you'll probably want a database table. Create an install.xml file in your db folder to set up your table structure. Moodle's XMLDB Editor is super helpful for this, it saves tons of time. You can access it through Site administration > Development > XMLDB editor.

When designing your table, you'll need to think about fields (like id, content, timecreated), keys (primary and foreign), and indexes for performance. Once that's done, you can use the $DB object to work with your data. For example, $DB->insert_record('your_table', $dataobject) to add stuff, or $DB->get_records('your_table', array('userid' => $USER->id)) to fetch records. The API makes database work much easier than writing raw SQL.
Making things look nice is important too. Just add a styles.css file for your custom styling. For any interactive stuff, load your JavaScript using $PAGE->requires->js(). Makes a huge difference to the user experience.
Watch out for some common mistakes, though. We often forget to check permissions properly when coding quickly. And we should never hard-code text—using language strings ensures that others can translate the plugin easily. Direct database queries might seem tempting, but they can cause major issues later if we don’t stick to Moodle's API. And yes, we should always test with different themes—we’ve spent hours debugging issues that only appeared with a specific theme.
Honestly, Moodle plugin development isn't as hard as people make it out to be. Start small and work your way up. The block we talked about is a perfect first project.
When you get stuck (and you will), the Moodle forums are amazing. Someone's always willing to help out. The developer docs are pretty good too, though sometimes a bit outdated.
Good luck! Hope this helps you build something awesome for your Moodle site.
Trusted by top platforms for our transformative solutions and exceptional results:






