How to add a Back button to blog post - Squarespace 7.1

Step 1

Open up the cog / settings of the blog post

Step 2

Click ‘Advanced’ then ‘Post Blog Item Code Injection’

Step 3

Copy and paste the below code in.

To update the text, change the URL “/news” to a link of your choice

Change the “Back to All Blogs” text to something more customised.

Step 4

Test and check your work

<!-- Back button for singular blog post -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  document.addEventListener("DOMContentLoaded", function() {
    // Target URL for the Back link
    const backUrl = "/news"; // Change this to whatever page you want

    // Add Back link before .blog-item-title
    const blogTitles = document.querySelectorAll(".blog-item-title");
    blogTitles.forEach(function(title) {
      const backLink = document.createElement("a");
      backLink.href = backUrl;
      backLink.className = "eventitem-backlink";
      backLink.textContent = "Back to All Blogs"; // Update this text to something customised
      title.parentNode.insertBefore(backLink, title);
    });
  });
</script>

<style>
  a.eventitem-backlink {
    display: block;
    text-align: left;
    margin-bottom: 0.5em;
    text-decoration: none;
    color: inherit;
  }
  a.eventitem-backlink:hover {
    text-decoration: underline;
  }
</style>
Dave Hawkins

As a top tier Squarespace Expert and founder of Made by Dave, I bring over 8 years of Squarespace experience and 200+ bespoke website launches. Our process combines consultancy, design, project management and development for a collaborative and efficient experience with clients like you. Whether you need a new website or updates for your existing site, we'll help you get up and running.

https://madebydave.org
Next
Next

How to have a the same image as the background perminantly - Squarespace 7.1