Writing: PHP

Function Friday #9: create a custom widget to list blog contributors

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”

Function Friday #8: add the blog page slug to single post permalinks

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”

Function Friday #7: send empty searches to the search results page

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”

Function Friday #6: add a class to the current content’s ancestor in the menu

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”

Function Friday #5: show custom image sizes in the attachment display settings

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”

Function Friday #4: add conditional classes to the body tag

If you haven’t spent time looking at WordPress starter/default themes, you may not have come across the body_class function before. It can be useful right out of the box for styling different types of content, but you can also conditionally add classes to this list for further styling.

Continue reading “Function Friday #4: add conditional classes to the body tag”

Function Friday #3: always show a second row of buttons in the Visual Editor

The second row of formatting buttons in the Visual Editor contains some useful ones, but it’s hidden by default. I don’t feel the couple pixels of space saved are worth potentially missing out on the added functionality, so I like to display the second row for all users.

Continue reading “Function Friday #3: always show a second row of buttons in the Visual Editor”

Function Friday #1: custom colour palettes in the Visual Editor

After I’ve launched a WordPress site for a client, I don’t want them to have to contact me to make any updates. To that end, I try to build in as many customization options for them as possible. One quick one is to show their brand/theme colours in the “Text color” colour picker instead of the default palette.

Continue reading “Function Friday #1: custom colour palettes in the Visual Editor”

I write about code, client resources, and nerdy things I like. You can jump straight to the technical stuff or the nontechnical stuff, or find specific topics below.