Every Mother

Add a copyright year programmatically to your website footer

A

Especially in January, you start thinking about copyrights on your websites. This is one of those maintenance tasks ripe for a programmatic solution. There is no reason to manually update the years on your website’s copyright year after year. Here are a few good options for creating an automatically updating copyright year on your website.

JS script and HTML Div

<script>
myDiv = document.GetElementById("myDivId");
myDiv.innerHTML = month[day.getMonth()]; // you can add any HTML markup here
</script> 
<div id="myDivId"></id>

Original inspiration from this post: fix without javascript error.


Change copyright year automatically with inline Javascript

<html>
<p>Copyright &copy; <script>now=new Date(); year=now.getFullYear(); document.write(year);</script> Company Name.</p>
</html>

If you’re using a visual builder in WordPress, remember you can often choose the Text tab instead of the Visual tab so that you can include a script in your text box.

If you're using a visual builder in WordPress, remember you can often choose the Text tab instead of Visual tab so that you can include a script in your text box.

PHP copyright year for WordPress PHP file

<p>&copy; <?php echo date('Y'); ?> Company Name</p>

HubSpot Copyright Variable for Year

 © {{year}} Company Name. All rights reserved.

Add Copyright to SquareSpace – Inline Javascript

You can use the code block in SquareSpace to add a copyright year. Here’s a video that shows you how to do it. For more details, check out our post about SquareSpace.

Add Copyright to Wix Studio Global Footer – Use Velo Code

Place this code in the MasterPage.js file. This code inserts the bolded code below (© year Company Name. All Rights Reserved.) into the text element with the id that matches #copyrightYear. Velo code runs during sitepublishing, so your site will always show the copyright symbol, current year and any company/rights text that you choose with this method.

$w.onReady(function () {
    const today = new Date();
    const year = today.getFullYear();

    $w('#copyrightYear').text = `© ${year} Company Name. All Rights Reserved.`;
});

This script looks for your text layer with the ID #copyrightYear. This is case-sensitive.

Give your text layer that you’re adding the automated script to the ID #copyrightYear.

Optionally, you can console log if your ID is working by adding these two console.log lines.

$w.onReady(function () {
    const year = new Date().getFullYear();
    const copyrightElement = $w('#copyrightYear');

    if (copyrightElement.rendered) {
        console.log("Copyright element found. Updating year...");
        copyrightElement.text = `© ${year} Company Name | All Rights Reserved.`;
    } else {
        console.log("Could not find element with ID #copyrightYear on this page.");
    }
});

About the author

Kelly Barkhurst

Designer to Fullstack is my place to geek out and share tech solutions from my day-to-day as a graphic designer, programmer, and business owner (portfolio). I also write on Arts and Bricks, a parenting blog and decal shop that embraces my family’s love of Art and LEGO bricks!

Add comment

Recent Posts

Archives

Categories