Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
Holli

How to display current year for copyright?

Question

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!

Edited by Testing2134
retag

Share this post


Link to post

6 answers to this question

Recommended Posts

  • 0

I think the only way you could do it is writing out the copyright notice and then remembering to update it. You’re right though, a more automated system would be a lot better.


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.

Share this post


Link to post
  • 0

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.

Share this post


Link to post
  • 2

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.

Share this post


Link to post
  • 0

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>


Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...