Moodle is very customizable and there are many custom themes available. But in some cases, you also may need to add your own HTML code to get what you want.

For example, you may want to add a simple Contact Form on your site. This can easily be done with an HTML Block or a Label, but if you have a custom theme (for example, Adaptable) that lets you add items into the Footer – you may prefer it there.

However, by default, Moodle will strip out some HTML that is added to areas that are not an HTML Block or a Label.

So instead of your contact form looking like this ?:

Correct Footer

It could end up looking like this ?:

Footer Incorrect

Adding HTML

Firstly you should ensure you are pasting the HTML correctly. Following the Moodle Docs page for the default Atto text editor, you need to expand the menu (labelled 1) and click the HTML button (labelled 18) to get to the HTML view.

Atto Image One

Atto Image Two



Then, you can paste in your HTML code and save changes. However, this is where you may find that Moodle will strip some of your HTML out and what you add will not look quite right!

The Fix

The fix for this is to “Enable Trusted Content” which you can do via ‘Site Administrator -> Security -> Site Policy’ – and tick – “Enable Trusted Content”.

This will tell Moodle to allow Site Administrators to add code into areas that Moodle will normally attempt to “clean” to avoid the possibility of any malicious script being added to your site. Be sure to read the description carefully!
This will only apply to Site Administrators (unless you give other roles this ability!) so you should have site administrators you can trust and your password policy is enforced correctly, to help avoid any possibility of malicious content getting on the site.

Once this setting is enabled, you can then go back to where you added the HTML code and add it again (remove the current code and re-paste). When you save it this time, Moodle will no longer attempt to clean the code and you should see the content you were expecting.

Success! ?

If you have any issues with your site, such as this one, check out our Technical Support services and get in touch!

About This Author

Dan Bennett

Dan has been working with Moodle since 2008, starting when Moodle was at version 1.9, having worked with customers from many backgrounds, supporting them with their Moodle sites when an issue arises – whilst also helping Moodle users in the Moodle Forums...