It is common to have a year in websites copyright section. Often times you will forget about this area for months or even years - meaning the date often gets out of date. In this post we will provide a quick way to find the file where copyright is rendered in Wordpress theme and how to make the date dynamic.
First step is to identify where the copyright is implemented. To do this use the browser dev tools and inspect the html. In our case we can identify the copyright text by class="copyright".
Next step is to identify where this piece of code is rendered. If you have an advanced IDE and the code base available you can simply search for this class. Otherwise you may need to look directly on the server. We usually use grep function to look for the piece of text we need.
root@localhost:/var/www/site# grep 'class="copyright"' . -irl
./wp-content/themes/i-transform/footer.php
./wp-content/themes/i-transform-child/footer.php
As you can see in the result above we found 2 files. Both are footer.php files but different themes. In our case we are using the child theme. So if we inspect the child theme file we can see the following code.
<footer id="colophon" class="site-footer" role="contentinfo">
<?php get_sidebar( 'main' ); ?>
<div class="row">
<p class="copyright">Techflare studio © 2020</p>
</div>
</footer>
As you can see the year is hard-coded. Our goal is to make it dynamic. We can do this easily by using the PHP inbuilt function date(). Change the snippet to following.
As you can see we are using the date() function to output the current date in format YYYY.
That is it. Now you have a dynamic copyright year and you can safely forget about changing it every year.