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” →
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” →
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” →