How do I add a date to my blog?

There are a lot of times when we want to add something as simple as the date to our blog …

There are a lot of times when we want to add something as simple as the date to our blog but coding (especially in PHP) can be a bit difficult. Let me walk you through the steps to adding a date to your blog, assuming of course you use WordPress.

First, open your template files such as the footer by loading the footer.php file located in your /wp-content/themes/[theme name]/ folder.

Next, we need to insert a very simple PHP function called date() into your page but before we do that, we need to make sure that we open and close the PHP event. To do this, simply open it using . The date() function itself requires a formating argument, but luckily we’re not meant to remember them all. They can be found on the PHP date() reference page.

As an example, if you want to show the day of the week that it currently is you could open your website and edit it every day (highly impractical) or you could insert the code into your page. Note that I open the PHP event, place the date() function with the argument ‘l’, indicate the end of a line (;) and then close the PHP event. Each of these elements are required to properly format the date.

If you would like to show the current year, simply use: because Y is the symbol for the year. On the other hand, if you’d like to use something more complex, try which will return something like Monday 8th of August 2005 03:12:46 PM.

Once you’ve saved your footer.php file, simply re-upload it to your server and voila! Now you can set the date using your server and PHP instead of editing files every day! In more practical terms, it is how you can always have an updated copyright notice of your website without having to remember to update it each January.

Leave a Reply

Your email address will not be published. Required fields are marked *