Add or Edit Shortcodes
To modify a shortcode that comes built-in with the Sans theme (or Hugo itself), you should mirror the theme’s structure in your root directory.
- Identify the shortcode name in
themes/sans/layouts/shortcodes/. - Create a matching file in your project root:
layouts/shortcodes/[name].html. - Add your custom HTML and Go template logic.
Action Path to Edit Result Modify Theme Shortcode layouts/shortcodes/notice.html Overrides the theme's version Modify Hugo Internal layouts/shortcodes/youtube.html Overrides the default Hugo YouTube embed Table: Overriding Logic
| Action | Path to Edit | Result |
|---|---|---|
| Modify Theme Shortcode | layouts/shortcodes/notice.html | Overrides the theme's version |
| Modify Hugo Internal | layouts/shortcodes/youtube.html | Overrides the default Hugo YouTube embed |
Adding New Shortcodes
You can create custom components (like buttons, alerts, or specialized galleries) by adding new files to your local layouts folder.
- File Location: Create
.htmlfiles inlayouts/shortcodes/. - Naming: Use lowercase names and hyphens (e.g.,
custom-button.html). - Accessing Parameters: Use
.Get 0for positional parameters or.Get "name"for named parameters.
Example: Creating a “Warning” Alert
Create layouts/shortcodes/alert.html:
| |