HUGO

How to avoid a shortcodes hell

I’m using several unstable supported themes. I use shortcodes to extend them.

Another reason for using shortcodes is that some functions should not be repeated in every archetype. It depends on the mind context of the article.

I stepped onto thin ice :cold_face:

There are already more than 10 shortcodes. And once again I need to update some of the articles to add a new shortcode.

What should I do? I don’t want to change the theme layer because I don’t want to depend on theme updates, I would rather use updates right away.

The real sample GitHub - contributorpw/google-apps-script-snippets-hugo-site: The Hugo static site for google-apps-script-snippets
At the moment, I only need to add shortcode {{< clipboard >}} to posts that contain copy code. Not every code needs to be copied.

You need to go through the Requesting Help guidelines and share a repository that reproduces the issues you encounter.

Also you need to be specific when opening a support ticket.
We cannot know what is going on from the above post.

IIRC, you can put shortcodes independently from the theme into the /_default/shortcodes/ folder, and Hugo will pick up these shortcodes. (If you have a shortcode with the same title both in the theme and in the repo, the one in the repo wins.) Or if you have multiple repos where you want to use these shortcodes, you can try to layer a separate theme that contains your shortcodes with the theme composition feature, see Add support for theme composition and inheritance · gohugoio/hugo@80230f2 · GitHub

2 Likes

It’s amazing!

I should definitely try composition instead of using the monolith theme.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.