Check Unused Templates or Shortcodes in Hugo (hugo --printUnusedTemplates)

This article explains how to check unused templates or shortcodes in Hugo.

To search for templates that are not used when building a Hugo site, use the --printUnusedTemplates option as follows.

% hugo --printUnusedTemplates
Start building sites …
hugo v0.111.3+extended darwin/arm64 BuildDate=unknown

...omitted...

WARN 2023/05/14 15:25:46 Template _default/list.rss.xml is unused, source file /Users/user/...omitted.../mysite/layouts/_default/list.rss.xml
WARN 2023/05/14 15:25:46 Template _default/single.html is unused, source file /Users/user/...omitted.../mysite/themes/docsy/layouts/_default/single.html
WARN 2023/05/14 15:25:46 Template blog/baseof.html is unused, source file /Users/user/...omitted.../mysite/docsy/layouts/blog/baseof.html

...omitted...

WARN 2023/05/14 15:25:46 Template swagger/single.html is unused, source file /Users/user/user/...omitted.../mysite/themes/mytheme/layouts/swagger/single.html
Total in 3146 ms

In the example above, you can see that several templates or shortcodes are not used.