Hi there, in this tutorial I will show you how to Automatically Update Copyright Year in WIX using Velo by WIX code. It is a common practice by many to manually go into their website's footer and change the year when the new year has just began. But this can be very demanding, especially for website owners with more than 1 website.
Using Velo by WIX code and a few lines of code, we will be learning how to display a dynamic copyright section in WIX.
ELEMENTS USED
Button or Text Element
UNDERSTANDING THE CODE
To get the site visitor's date and time, we use the newDate Method
According to W3Schools,
JavaScript Date Object lets us work with dates:
The newDate method provides a huge information about our date and time. Since it is an object, that means we will need an extension to only get what we are looking for (Current year). For that purpose, we use the getFullYear() Method. Which is defined as;
getFullYear() returns the full year (4 digits) of a date.
Finally, we find a way to display this information on our text or button element (Basically any element that allows us to display text).
For this purpose we use Template Literal. According to Mozilla Developers
Template literals are literals delimited with backticks (`), allowing embedded expressions called substitutions.
Untagged template literals result in strings, which makes them useful for string interpolation (and multiline strings, since unescaped newlines are allowed).
Tagged template literals call a function (the tag function) with an array of any text segments from the literal followed by arguments with the values of any substitutions, which is useful for DSLs.
Template literals are sometimes informally called template strings, but they aren't string literals and can't be used everywhere a string literal can be used. Also, a tagged template literal may not result in a string; it's up to the tag function what it creates (if anything).
// Untagged, these create strings:
`string text``string text line 1
string text line 2`
`string text ${expression} string text`
// Re-usable template:
const templateFn = expression => `string text ${expression} string text`;
// Tagged, this calls the function "example" with the template as the
// first argument and substitution values as subsequent arguments:
example`string text ${expression} string text`
COPY CODE BELOW 👇🏽
Code
Leave a comment (0)
Thanks for leaving a comment🎉