Adding "Edit this page" links

Here’s how the cool Hugo/Wowchemy kids add those groovy “Edit this page” elements to their pages in the academic-starter theme:

In config/_default/params.yaml, find the section edit_page and:

☞︎ Set repo_url to the URL of your repository (here, github)
☞︎ Set content_dir to the directory of your site’s content, content by default)
☞︎ Set repo_branch to your repo’s published branch; I use master rather than main)

Then set the editable fields as needed for the types of content you want these links to be present in.

Here’s the code from this site:

  repo_url: ''
  content_dir: 'content'
  repo_branch: master
    page: true
    post: true
    book: true

That’s all you need to do; when you rebuild, if the edit_page parameters are not empty, Hugo will insert the link as directed by the templates. This is the bit of triggering code:

{{ partial "page_edit" . }}

It is contained in various inherited templates such as themes/, and the code is in themes/

Look at the code to see, among other things, that it can be overridden on a specific page or post by adding editable: false to its yaml header.

But we’re not doing that in this case, so falling off the bottom of the content here, we get the groovy link to the page source below (note, you’ll need to fork the repo to actually see it, it’s more for me than for you):

Edit this page

Steve Linberg
Steve Linberg
Masters student in Data Analytics and Computational Social Science at the University of Massachusetts Amherst

Programmer since before you were born. Sysadmin/DBA for a couple decades. Painter in a parallel universe. Now a student again.