Category: Code

Featured Image Fallback for Child Pages

Continuing on from the same project where I needed to highlight a parent page in a WordPress menu when on a child page, featured images is another place where I wanted some custom functionality. This custom functionality I’m about to share wasn’t necessarily a requirement but I wanted to make it as simple as possible for […]

Highlighting parent page in WordPress menus

Menus in WordPress are a really simple and easy way to manage various navigation bars in a theme. wp_nav_menu() does a lot of the work automatically and includes a number of CSS classes for styling. Highlighting the current page is especially useful using .current-menu-item and .current-menu-ancestor classes. There was one issue I recently ran into though. […]

Gravatar Is More Than Just An Avatar

Personal profile websites are a common sight these days, especially when services like make it so easy for everyone to have one. But did you know Gravatar can do more than just serve your avatar around the websites you frequent? Gravatar provides a personal profile that people can view to learn a little more […]

Tip: str_replace()

Here’s a quick little tip for using PHP’s str_replace() with many values. Sometimes it’s fine to just do this: $string = str_replace( ‘to_replace’, ‘replacement_string’, $string ); $string = str_replace( ‘to_replace’, ‘replacement_string’, $string ); $string = str_replace( ‘to_replace’, ‘replacement_string’, $string ); That method is fine but can get messy with many replacements. Another method is to […]

Postmark API Wrapper for CodeIgniter

Notice: This project is no longer maintained. I’ve been using Postmark and it’s API for quite a while. If you’re still sending out emails through PHP’s mail() function, you need to check out Postmark! With Postmark you can off-load those transactional emails and not have to worry about it yourself. While there is a Postmark API […]

Refactoring in Practice

I love taking larger functions and slimming them down into a more efficient and readable format. Here is a simple example of just that. The original function: function strip_slashes( $data ) { if( is_array($data) ) { foreach($data as $key => $val ) { $data[$key] = strip_slashes($val); } } else { return stripslashes($data); } return $data; […]

CodeIgniter Form with Text CAPTCHA

“A CAPTCHA (Completely Automated Public Turing Test To Tell Computers and Humans Apart) is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot.” – The current CAPTCHA system I started using is Text CAPTCHA. The Text CAPTCHA web service generates text-based CAPTCHAs which […]

Directory Listing from a Path

$path = dirname( __FILE__ ); $listing = array_filter( scandir( $path ), function( $var ) { // remove special directories ‘.’ and ‘..’ from listing if ( preg_match( ‘/^[.]{1,2}$/’, $var ) ) { return FALSE; } // remove files from listing if ( !is_dir( $var ) ) { return FALSE; } return TRUE; } ); This […]

Validate terminal command in PHP

Testing if a function exists in PHP is easy. Testing if a command exists on the system is also easy. I’ve never really run into the problem of having to create a compatibility suite script to make sure my PHP script will run without trouble. Simple things like checking the version of PHP installed or the […]

Modular Sidebar in WordPress

Like all good developers, I go back and look at past code to see what I could have improved and how I can apply the new knowledge to a current project. Both of the projects in question had sidebars with sections that are shared throughout the site. However, not all sections are being displayed at […]