How can I automatically update the copyright date on my Webflow site's footer each year?

Published on
September 22, 2023

To automatically update the copyright date on your Webflow site's footer each year, you can utilize a combination of Webflow's dynamic data and custom code. Here's a step-by-step guide on how to achieve this:

  1. Create a new field in your CMS Collection: Start by adding a new field to your CMS Collection to store the copyright date. You can name the field whatever you prefer, such as "Copyright Year."

  2. Set the default value for the copyright date field: Set the default value for the copyright date field to the current year so that it will always be up to date. To do this, go to the Collection Editor and select the field you just created. Next, click on the pencil icon to edit it and set the Default Value to the following custom code:

{{'Now' | date: "%Y"}}

This code will output the current year.

  1. Add the dynamic copyright year to your footer: In your footer design, add a text element where you want the copyright year to be displayed. Double click on the element to enter its settings, and then select "Dynamic" under the Text section. Choose the CMS item you want to pull the copyright year from, and select the "Copyright Year" field.

  2. Custom code for updating the copyright year: Lastly, to ensure the copyright year updates to the current year automatically, you will need to add a small piece of custom code in the site's footer. Open the custom code section of your site settings, and paste the following code before the closing </body> tag:

<script>  const date = new Date();  const year = date.getFullYear();  document.querySelector("#copyright").textContent = year;</script>

Make sure to replace #copyright with the correct element ID or class name that you used for the copyright text element in your footer.

Now, whenever a new year begins, the copyright year in your Webflow site's footer will automatically update to the current year. This ensures that your site is always displaying the correct copyright information.

Additional Questions:

  1. How do I create a dynamic data field in Webflow CMS?
  2. Can I update other dynamic data on my Webflow site using custom code?
  3. Is it possible to display the current month or day using Webflow CMS and custom code?