Writing: PHP

Function Friday #15: display different navigation menus on child pages

On a massive site with lots of parent and child pages, you may not want to have a mega-menu with every single page in it. A possible solution is to conditionally display a second level of navigation, which contains different submenus depending on which page you’re viewing. What about dynamically creating menu locations based on your current page hierarchy?

Continue reading “Function Friday #15: display different navigation menus on child pages”

Function Friday #14: include website documentation within the admin area

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”

Function Friday #12: include code in your content with a custom shortcode

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”

Function Friday #11: displaying menu item descriptions with a custom walker

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”

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”

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.