Hi everyone,
Here’s a quick guide to add custom JavaScript to your Flarum admin panel. You have two simple options:
Option 1: Local JS File
- Open your
extend.php file and add:
<?php
/*
* Customization by Hüseyin Filiz (github.com/huseyinfiliz)
*/
use Flarum\Extend\Frontend;
use Flarum\Frontend\Document;
return [
(new Frontend('admin'))
->content(function (Document $document) {
$jsContent = file_get_contents(__DIR__ . '/admin_custom.js');
$document->head[] = "<script>\n" . $jsContent . "\n</script>";
})
];
- In your root directory, create a file named
admin_custom.js.
- Add your JavaScript code without
<script> tags.
- Clear the cache after saving. ✅
Option 2: External JS File (Single JS for Multiple Sites)
- Open your
extend.php file and add:
<?php
/*
* Customization by Hüseyin Filiz (github.com/huseyinfiliz)
*/
use Flarum\Extend\Frontend;
use Flarum\Frontend\Document;
return [
(new Frontend('admin'))
->content(function (Document $document) {
$externalJsUrl = 'https://flarum1.huseyinfiliz.com/admin_custom.js';
$document->head[] = '<script src="' . $externalJsUrl . '"></script>';
})
];
- Clear the cache after saving. ✅
This method allows all your Flarum sites to load the same JS from a single URL.
Both methods are simple and effective. Pick the one that suits your setup, and enjoy customizing your admin panel!
💖 This development was created to support @KBExit's requirement for injecting JS code into the admin panels of customer forum sites hosted on their own platforms.