As a WordPress developer, there are often little “gotchas” I find when creating or editing themes. This article is the first in a series where I’ll be documenting some of my findings in an effort to help other developers avoid the same mistakes. If you have any of your own WordPress development gotchas that you’d like to share, let me know on Twitter.
Incorrect Copyright Year Displaying In Footer
Many websites display the copyright year in the footer, but if you’re using
the_date('Y'), the incorrect year could show up. I came across this issue on this site when I noticed the year still said 2015 for some reason. WordPress’
the_date() function is looking for the publication date of the current page, not the current date. This can yield unexpected results for pages that don’t get updated often or pages that aren’t actually published, such as 404 or archive pages. To avoid this, use PHP’s
date() function instead, which you can read up on here.
Custom Post Types Not Showing Up
Although I’ve been creating my own custom post types for over a year now, I came across an issue where one of my newly created custom post types would not appear in WordPress. I looked over all of my code, but everything was set up the same way it had been countless times before with no issues. On a whim, I decided to change the name of the post type when registering it and that did the trick. WordPress actually limits the names of custom post types to 20 characters and it cannot be changed, so keep this in mind when creating new custom post types. In addition to simply not showing up, having a name over twenty characters can lead to other unexpected issues, such as being unable to create or publish new posts.
Uploaded Images Not Displaying On Secure Site
While working on a client site, I received a complaint that none of the images the client was uploading were showing up on their site. After a couple of my own tests, I found that the uploaded images were being delivered through
http instead of
https, even though it was a secure site. This meant the images were loaded over an insecure connection, so they would appear broken on both the front-end of the website and the WordPress admin. We had recently switched their site over to
https, but had not updated the WordPress URL to match, which was causing the issue. Under Settings > General in WordPress, update the WordPress Address along with the Site Address, if you are using it. This should alleviate the mixed content warnings and your images should display properly across the site.