Writing: Code snippets

Function Friday #18: hide the admin area and toolbar from certain user roles

WordPress is a great platform for membership-based sites, where lots of people can log in with very specific, restricted access to certain areas. Unless some of the functionality they need access to is in the admin area, I usually disable it for everyone except the roles that do need access. With a few functions, you can more or less completely hide the fact that your site is running WordPress (unless you have savvy visitors who notice things like “wp” in the login URL).

Continue reading “Function Friday #18: hide the admin area and toolbar from certain user roles”

Function Friday #17: clean up custom post types created by a plugin or theme

If you have a plugin or theme that creates its own custom post types and/or taxonomies, you might want to override some of them. You shouldn’t edit the plugin/theme code directly, because then you can’t apply future updates without losing your changes. WordPress has a few functions that will let you do it in a non-invasive way. You can even use them to remove taxonomies or features from built-in post types like Posts or Pages.

Continue reading “Function Friday #17: clean up custom post types created by a plugin or theme”

Function Friday #16: add an accessible post link to manual & automatic excerpts

When you’re displaying lots of blog posts in a row and you don’t want to show the entire post, you can use the WordPress excerpt function. You might want to change the default number of words, or add a link to the post instead of an ellipsis. While you’re at it, you could also make the post link more useful for visitors that are accessing your site with a screen reader.

Continue reading “Function Friday #16: add an accessible post link to manual & automatic excerpts”

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”

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.