From the course: WordPress Development: Coding Practice
Dynamic copyright year - WordPress Tutorial
From the course: WordPress Development: Coding Practice
Dynamic copyright year
- [Instructor] We are going to start off with a common problem on websites, a hard-coded static copyright year that needs to be updated manually. Many websites require manual updating of the copyright line when the calendar year changes. So the requirements for this challenge are to create a function using the provided code that dynamically gets the current year and displays it. You should pick a start year for the copyright line, I'll be using 2003 because that's when I first started my blog. As a quick note, many of these examples will include short codes for displaying the results. That way we will be fully backwards compatible with WordPress. We don't need to worry about JavaScript or block development, and we won't need to worry about sites that do or do not support full site editing. Your starting code can be found in 01-01-start. All of the challenges will be plugins that you can add to WordPress. Use this as your starting point. Pause the video here and unpause it when you're ready to see my solution. (upbeat music) Welcome back. So this is going to be a one line solution and because we're using a short code we want to return the value. The short code functionality in WordPress will make sure that the information is outputted. So we're going to type return and then we'll use single quotes. I will use the HTML entity for the copyright symbol which is ampersand, copy, and then the semicolon. I'm going to write 2003 space dash and then space. Remember, we want to include a space inside of our static string inside of our quotes so that we don't have text colliding with one another. And then we'll add the period for concatenation. We'll use the built in date function in PHP with a capital Y to display the four year or the four digit year. Then a semicolon. We'll save this and then we will go ahead and upload it to WordPress and give it a test. So I have already installed the plugin over at plugins, add new, I've uploaded it already and I have a page that I'm using as a test page in my WordPress installation where I have the short code in the short code block. We'll click update and then we'll view this page and you'll see the copyright line displayed here. If you are using full site editing, you could always add it to the template, but again, we don't want our code to rely on that.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Dynamic copyright year2m 50s
-
(Locked)
Randomize posts5m 37s
-
(Locked)
Get post meta3m 19s
-
(Locked)
Change admin colors based on the server5m 18s
-
(Locked)
Create your own block pattern5m 58s
-
(Locked)
Append a message to RSS content5m 31s
-
(Locked)
Sanitize input4m 39s
-
(Locked)
Sanitize output4m 4s
-
Add a sitewide banner to the top of the page3m 32s
-
(Locked)
Register a custom post type5m 37s
-
(Locked)
Store user meta5m 29s
-
(Locked)
Send an email to the admin when a plugin is activated6m 42s
-
(Locked)
When a user logs in, greet them by their name4m 44s
-
(Locked)
Create a transient5m 30s
-
(Locked)
Hide content based on a query string5m 49s
-
-