Jump to content

How to display current year for copyright?

Recommended Posts

I’ve searched through the Answers and searched online and haven’t found an answer to this. All I want to be able to do is add a copyright notice with the current year in the footer.

The only answer I’ve found says to use jQuery. I think it’s ridiculous to load jQuery just for that, and I really would rather get the year from the server and not the client. Why isn’t there a block or something for this? This has to be a common problem. Is there a way to do this that I’m just missing? Thanks!

Link to comment
  • Replies 6
  • Views 21.7k
  • Created
  • Last Reply
  • 4 weeks later...

It would work, but as @Holli says – using jQuery which is then loaded and run every single time on every single page view is overkill. Every bit of dynamic content puts more load on the visitors computer (or tablet, or phone…) and the one thing Squarespace pages don’t need is more heft.

The name is an Anglicised form of the Greek Korvetti — I like to think there’s a little bit of the ancient Hellenic drive in me.

Link to comment
  • 1 year later...

You don't need jQuery to get the current year. Plain old javascript can do that just fine, but if you want other text with the current year you'll need to add that in to the javascript as well.

Insert a code block in your Footer section. select HTML as the type and make sure "Display Source" is unchecked. Then paste the following code.


<script type="text/javascript">
 var date=new Date(),
     year = date.getFullYear(),
     text = "Copyright " + year + " - YOUR COMPANY NAME",
     html = '<div class="text-align-center">' + text + '</div>';

 document.write(html);
</script>

If you don't want the text aligned to the center you can remove "text-align-center" from the div's class.

Hope that helps.

Link to comment
  • 10 months later...
  • 11 months later...

I used the code that nickporter provided (thanks Nick!) but for some reason the document.write function was overwriting the html on the entire page, so my site turned into a blank page with one line of copyright info at the top. If anyone else runs into the same problem just create an empty div right above the script (in the same code block) and instead of document.write() use document.getElementById().innerHTML(). Example below.


<div id="copyrightOutput"></div>

<script type="text/javascript">
 var date=new Date(),
       year = date.getFullYear(),
      text = "© " + year + " Your Company Name";
 document.getElementById("copyrightOutput").innerHTML=text;
</script>


Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.