Extend & Customize HugoBlox
HugoBlox is designed to be extensible. Whether you need a simple CSS tweak or a complex third-party integration, you can do it without modifying the core theme files.
Inject custom code (like analytics, popups, or meta tags) into specific parts of your site using Hooks.
| Hook | Description | Common Use Cases |
|---|---|---|
head-end | Just before </head> | Meta tags, tracking scripts |
body-end | Just before </body> | Chat widgets, analytics |
footer-start | Inside footer | Custom copyright, links |
- Create the hook file path.
- Add your HTML/JS code.
Directorylayouts/
Directorypartials/
Directoryhooks/
Directoryhead-end/
- custom-meta.html
Directorybody-end/
- analytics.html
Example: Add a Script
Section titled âExample: Add a ScriptâTo add a custom script to the end of the body:
-
Create
layouts/partials/hooks/body-end/myscript.html. -
Add your code:
<script>console.log("Hello from custom hook!");</script>
Custom Styling (CSS)
Section titled âCustom Styling (CSS)âOverride or add new styles.
-
Create
assets/css/custom.css. -
Add your CSS.
assets/css/custom.css .my-custom-class {color: red;}
Overriding Components
Section titled âOverriding ComponentsâHugoâs Lookup Order allows you to replace any official layout file by creating a copy in your local layouts/ folder.
-
Identify the File Find the file you want to change in the HugoBlox repository.
- Example:
layouts/_partials/components/headers/navbar.html
- Example:
-
Copy to Local Create the same folder structure in your site root and paste the file.
- Example:
layouts/_partials/components/headers/navbar.html
- Example:
-
Modify Edit your local copy. Hugo will use it instead of HugoBloxâs version.
Advanced Customization
Section titled âAdvanced CustomizationâCreating New Blocks
Section titled âCreating New BlocksâUse the Blox System to create reusable content blocks.
sections: - block: my-custom-block content: title: My BlockCreate your Go HTML template at layouts/_partials/hbx/blocks/my-custom-block/block.html.
Check out the existing blocks for inspiration.
Theme-Aware JavaScript
Section titled âTheme-Aware JavaScriptâListen for theme changes (Light/Dark mode) in your custom scripts.
document.addEventListener('hbThemeChange', (e) => { const isDark = e.detail.isDarkTheme(); console.log('Theme changed to:', isDark ? 'Dark' : 'Light');});