Why use a dynamic timestamp in your footer?
When you surf the web, have you ever looked at a website and wondered if it was still in operation? Maybe a few things looked like they had been updated, but then you notice the copyright notice the in the footer… “2012“?!? This site must have been abandoned, right?
Of course, it could be that the owner just forgot to update the year in the footer. That happens a lot, especially if that year was simply a text string. To future-proof your footer, it’s better to just let coding take care of this. If you’re comfortable with editing html code, you can just use one of these snippets on your page. If you aren’t comfortable, just contact NDesign, and let us take care of this for you!
Bring it up to date, and keep the site alive! Happy New Year from NDesign!
JavaScript Code
This is straight JavaScript, meaning it will refresh the year browser-side, depending on the user’s time settings. Just copy the below snippet and paste it where you want your dynamic text to appear.
document.write(new Date().getFullYear());
</script>
This will just give you:
If you want a bit more information, here’s a snippet you can customize:
This will give you:
Because JavaScript works in the user’s browser, the date that actually appears is dependent on the user’s settings. In most cases it will likely be what you’d expect.
PHP Code
Here’s the same info in PHP, so you can do this server-side. Use WordPress? Find the ‘footer.php’ in your Editor and add this there (be very careful if you aren’t familiar with how to do this!). The below snippet will just show the current year:.
This will give you:
Or, if you want more information:
$fromYear = 2007;
$thisYear = (int)date(‘Y’);
echo $fromYear . (($fromYear != $thisYear) ? ‘-‘ . $thisYear : ”);?> Company.
Or, you can use ($fromYear < $thisYear) in the above to account for any time reversal, or a confused server, more likely. Either will give you:
Since PHP works on the server, it will display the year the server is currently using.