Writing: Code snippets

Function Friday #23: close your menu if a same-page anchor is clicked

Single-page websites and minimized-by-default menus are both really popular at the moment, and the combination of the two can cause an interesting problem. When these menus are expanded, combined with anchor links that just jump down the page instead of reloading it, you can end up with a menu covering your content.

Continue reading “Function Friday #23: close your menu if a same-page anchor is clicked”

Function Friday #22: get dynamic information about your Posts page

If you’ve got a static page as your front page and another page containing all of your posts in your Reading settings, it’s likely that you’ll want to link to that Posts page somewhere on your site, use its page title, or even display its featured image. Rather than hard-coding this into your theme, there’s a function that will grab the page’s ID so you can display that information dynamically.

Continue reading “Function Friday #22: get dynamic information about your Posts page”

Function Friday #21: add conditional comments to enqueued scripts

There are tons of articles about how to include scripts in your WordPress theme, usually with things like “properly” and “the right way” in their titles. When it came to scripts that need to be wrapped in conditional comments for IE, though, I was still printing them directly. I didn’t know how to include those comments in the enqueue function until I stumbled across a function that lets you do it all in one place.

Continue reading “Function Friday #21: add conditional comments to enqueued scripts”

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”

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.