Shortcode to Add a Strikethrough

Edit 21/02/2023:

There’s a much easier way to do this when using markdown, by using a tilde character twice. In your markdown for your post or page, wrap the text in a double ‘squiggle’ character and it will strike it out. See our example below

1
~~Example~~

Looks like: Example

(thanks stp in the comments)

Original Post:

This is part of our Hugo shortcode series.

In this post we wanted to make a quick shortcode to add a strikethrough to some of our text. We use a very similar method to the raw html shortcode, but encompass it with the <strike> element.

Like this text here.

File: /layouts/shortcodes/strike.html

1
<strike>{{.Inner}}</strike>

Example Usage

1
Welcome to {{< strike >}}MakeWithHugo{{< /strike >}}

Output

1
<strike>MakeWithHugo</strike>

Welcome to MakeWithHugo