Drupal 8 - Add a link to create content in the view header or footer

By xngo on March 30, 2019

To add a link in your view header to create a content type, do the followings:

  • Open your view.
  • Under the HEADER section, add the following code in your Global: Text area:
[ <a href="/node/add/trade?destination=/trade-alerts">Add Trade</a> ]
  • Make sure that you set your Text format filter to FULL HTML.
  • Replace trade with your own content type machine name.
  • ?destination= will redirect to the destination path after content is saved.
  • Repeat the same steps for FOOTER section.
  • Optional: check Display even if view has no result.

The end result will look like the followings: Screenshot of add link in view header

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.