How to get current year shortcode on WordPress – JavaScript

  • Home
  • How to get current year shortcode on WordPress – JavaScript
How to get current year shortcode on WordPress – JavaScript

This is very important to show the current year on the footer for copyright purposes.
But sometimes we can’t do it because of the theme rules. Some WordPress themes have the permission to show the dynamic display of the current year on the footer only. If we edit the footer by using Elementor or we use the theme “current year” shortcode anywhere, it does not work.

If we use JavaScript then this will be solved.
Use the code on your WordPress backend and see the magic.

window.addEventListener('load', (
    function () {
        document.getElementById('copyright-year').appendChild(
            document.createTextNode(
                new Date().getFullYear()
            )
        );
    }
));

In this case, “copyright-year” this is the CSS ID. you can use it with span tag that’s good actually.

See the example below:

Copyright <span id="copyright-year">©</span> Sefatun. All Rights Reserved.

Note: this plugin can help you add code in the head or body “Simple Custom CSS and JS“.

Leave a Reply

Your email address will not be published.