Building With

GenerateBlocks

Useful tips for building advanced blocks.

Force Download Button

When you click on a link to an image, WordPress generally opens the image on the same page or a different page. It does not give you the option to download the image.

For my Doodle Line Icons project, I wanted to allow users to directly download the SVG file rather than opening the file on a separate page, then having to right-click on the image to save it.

One workaround is to use the download attribute as in the example below.

<a href="/uploads/doodle-line/Chat-Text-Right.svg" download>

1

Add a Button (from the GenerateBlocks plugin, not the default option from WordPress) and insert the link to the file you wish users to download.

Adding Link v1

2

Click on Advanced on the right-hand side and scroll to the bottom. You should see an option to add Custom Attributes.

Advanced Add Attribute

3

Type download into the field and click on Save as Draft or Publish the article.

Add Attribute Download

Final Results

Click on Preview > Preview in a new tab. On the preview page, click on the Download button, it should allow you to download the file directly.

Leave a comment