Posted on April 21st, 2017 in Technical: Code snippets, PHP, WordPress
When a project’s deliverables include a how-to manual, it’s often done as a PDF that’s totally separate from the website. I started including the documentation I write in the same place that people will be working on the website: within the admin area itself. This way it never gets lost as a result of staff turnover or file purges.
Continue reading “Function Friday #14: include website documentation within the admin area” →
Posted on April 14th, 2017 in Technical: Code snippets, PHP, WordPress
Did you know that all time/date-based functions in PHP use UTC time? Based on how often I come across this issue I don’t think many developers do! I certainly didn’t until I was working on a site that displayed different content based on the current time.
Continue reading “Function Friday #13: use the correct timezone in time-based functions” →
Posted on April 7th, 2017 in Technical: Code snippets, PHP, WordPress
For a variety of reasons, WordPress will strip out a lot of code you may want to paste into the editor (even if you’re on the Text tab). If the code you’re pasting has lots of line breaks to improve readability, WordPress will also convert line breaks to br and p tags.
Continue reading “Function Friday #12: include code in your content with a custom shortcode” →
Posted on March 31st, 2017 in Technical: Code snippets, PHP, WordPress
Have you ever wondered about the “Description” field on the Appearance → Menus page, with its notice that “The description will be displayed in the menu if the current theme supports it”? I’d seen it before (when enabling the “CSS Classes” field via Screen Options) but hadn’t paid much attention to it, until I had a client that wanted some text to appear next to each item in the navigation menu.
Continue reading “Function Friday #11: displaying menu item descriptions with a custom walker” →
Posted on March 24th, 2017 in Technical: Code snippets, PHP, WordPress
When I need a way to change content on a page based on how the visitor got there, I usually rely on query strings in the URL. You can use this technique to (for example) show different tax-inclusive prices to people depending on their location.
Continue reading “Function Friday #10: change content based on query strings” →
Posted on March 17th, 2017 in Technical: Code snippets, PHP, WordPress
A fairly common request I get is to have a list of my client’s blog contributors in the sidebar. It’s odd this isn’t one of the default WordPress widgets, to be honest! But it’s easy to add with a bit of code. You can also further customize the widget using the plugin Advanced Custom Fields.
Continue reading “Function Friday #9: create a custom widget to list blog contributors” →
Posted on March 10th, 2017 in Technical: Code snippets, PHP, WordPress
If a site is using WordPress posts for non-time-sensitive content (like this one), I’ll often remove the date from the permalinks. On a site that’s using a Posts Page I’ll also add the slug from the Posts Page into the URL of all posts, plus all category and tag archives. It’s a small detail that makes finding your way around the site just a little bit easier.
Continue reading “Function Friday #8: add the blog page slug to single post permalinks” →
Posted on March 3rd, 2017 in Technical: Code snippets, PHP, WordPress
One of the things I test on every site I build is to run a search, and one time I accidentally did it with an empty search form – just hit enter without filling in any keywords. To my surprise I was redirected to a page that showed the latest blog posts instead of the search results page I expected.
Continue reading “Function Friday #7: send empty searches to the search results page” →
Posted on February 24th, 2017 in Technical: Code snippets, PHP, WordPress
Sometimes a tiny design change can make navigating a website much easier. Indicating which page you’re currently on by changing the style of the corresponding menu item is one of those changes, and WordPress helps you out by adding a bunch of classes to every menu item – but not once you add custom post types into the mix.
Continue reading “Function Friday #6: add a class to the current content’s ancestor in the menu” →
Posted on February 17th, 2017 in Technical: Code snippets, PHP, WordPress
I often find the default image sizes generated by WordPress (Thumbnail, Medium, and Large) aren’t sufficient to cover every situation where I want to use images of a specific size. And once you’ve set up a bunch of custom image sizes, you might want to insert them into your posts and pages, not just use them in your theme code.
Continue reading “Function Friday #5: show custom image sizes in the attachment display settings” →