Posted on June 30th, 2017 in Technical: Code snippets, PHP, WordPress
While it’s great to avoid cowboy coding by having both local and staging versions of your live website, I’ve come across themes that indiscriminately load code on all three environments. You can use the same theme/plugin files on different environments, you just have to check where you are before loading environment-specific content.
Continue reading “Function Friday #24: check your environment before loading code” →
Posted on June 16th, 2017 in Technical: Code snippets, PHP, WordPress
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” →
Posted on June 9th, 2017 in Technical: Code snippets, PHP, WordPress
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” →
Posted on June 2nd, 2017 in Technical: Code snippets, PHP, WordPress
If you love custom post types as much as I do, you may have wished for a “Posts Page” setting for the custom post type archive. Or maybe you want to separate Posts from (for example) Press Releases on the back end, but they should display mixed in together on the front end.
Continue reading “Function Friday #20: add custom post types into the main loop” →
Posted on May 26th, 2017 in Technical: Code snippets, PHP, WordPress
Gravity Forms is a super-powerful form builder plugin that I’ve used for all kinds of client projects. Recently I had to figure out how to get their Post Fields to send to a custom post type, instead of the default Posts.
Continue reading “Function Friday #19: publish user content to custom post types with Gravity Forms” →
Posted on May 19th, 2017 in Technical: Code snippets, PHP, WordPress
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” →
Posted on May 12th, 2017 in Technical: Code snippets, PHP, WordPress
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” →
Posted on May 5th, 2017 in Technical: Code snippets, CSS, PHP, WordPress
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” →
Posted on April 28th, 2017 in Technical: Code snippets, PHP, WordPress
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” →
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” →