By Tyler Morgan.
I've had a hard time finding a simple way to update copyright footers for my web pages. All of the solutions either collect data from the user and/or don't provide the copyright types I need. So I made my own that suits my needs. Maybe someone has created something similar, but it was not easy enough for me to find. So I'll contribute more code I guess!
- Create a lightweight JavaScript file.
- Create both static and dynamic years and year ranges.
- Reduce reliance on
id
attributes. - Reduce data collection when retrieving the current year for users.
- Minimal updating of the file (one string change per year).
- Simple syntax when setting up copyright years.
If you just want to update the year to the current year (e.g., © 2025 Tyler Morgan. All rights reserved. or whatever), I gotcha covered.
Add data-copyright-currentyear
to any HTML tag. Preferably an empty span
. You can leave the attribute value empty. Example: <span data-copyright-currentyear></span>
will spit out "2025" (since the year is 2025 when I'm writing this).
If you just want to add the copyright year of a work, no current year needed. This will suit you. Of course, you can just manually add the year in the text content, up to you, whatever floats your boat.
Add data-copyright-year="YYYY"
to any HTML tag. Preferably an empty span
. Change out "YYYY" to the year you want, obviously. Example: <span data-copyright-year="1973"></span>
will spit out "1973".
If you're looking to add a year range that updates the ending number to the current year (eg., © 2020-2025 Tyler Morgan. All rights reserved.), this is the one for you.
Add both data-copyright-year="YYYY"
and data-copyright-endyear="currentyear"
to any HTML tag. Preferably an empty span
. Change out "YYYY" to the year you want, but "currentyear" should be left as is. Example: <span data-copyright-year="2004" data-copyright-endyear="currentyear"></span>
will spit out "2004-2025". If you change out "currentyear" to "currentyear2", it will display the last two digits of the current year. Example: "2020-25".
Do you just want an unchanging year range? Cool, I got that too.
Add both data-copyright-year="YYYY"
and data-copyright-endyear="YYYY"
to any HTML tag. Preferably an empty span
. Change out "YYYY" to the year you want. Example: <span data-copyright-year="1996" data-copyright-endyear="2013"></span>
will spit out "1996-2013".
The data-copyright-year
and data-copyright-endyear
are string values if you need to add lettering to the years. If for whatever reason you need BC or AD, you can totally do so. Or you can switch the years to two digits. To each their own!
Just change the currentYear const on line 1 in the file to whatever year it currently is. This is done once a year, and then all of your websites are updated!
Feel free to open an issue!