quick tip

WordPress Helper Functions for Detecting IE

The other day I was working on a problem where I wanted to check if a website was using a specific browser (in this case IE) and version (in this case 9 or below). I came up with 2 functions that would serve an a nice, reusable check for both. These can also be extended to check for other browsers or versions, or even accept custom regular expressions.

Add Attachments to WordPress Search Results

I feel like this has to have been done a lot, and there are great plugins out there for it, but if you’re just looking to add a quick function to your theme (or a really simple plugin) yourself, here’s how to modify WordPress’ search query to include attachments (like images).

function attachment_search( $query ) {
    if ( $query->is_search ) {
       $query->set( 'post_type', array( 'post', 'attachment' ) );
       $query->set( 'post_status', array( 'publish', 'inherit' ) );
   return $query;

add_filter( 'pre_get_posts', 'attachment_search' );

This does 2 things: includes posts of type ‘attachment’ to the search query, and adds the post status of ‘inherit’. This will ensure that any images (or other attachments) that were added while adding a new post or page will be included in the results.

You can also extend the post type array to include your own Custom Post Types (eg array(  'post', 'attachment', 'products' ); )

These 2 posts were very helpful in getting this code together:

Quick Tip: How to Un-shrink a Sweater

So this isn’t really tech related, but I’m a guy and not a very bright one at that. Last week a bought a new sweater, wore it out over the weekend and had to wash it. I of-course ignored the dry-clean only label and my brother’s warning and threw it in with the rest of the clothes. The result is that it was about 3 times smaller. Luckily I took to the Internet and found this awesome site, detailing how to un-shrink the sweater.

  1. Soak the sweater in warm water with a mild soap for about 10 minutes.
  2. Lay the garment out on some towels in a cool place (I hung it up on a hanger).
  3. Stretch the sweater out to its original size.
  4. Allow it to dry.

The website explains in a little more detail the whys, but I tried this and it worked. If you try it, good luck! Let us know in the comments if it works. Other tips are also welcomed!

Quick Tip: How to Move a WordPress Site

I won’t go too in-depth here, but I will describe the steps you need to take to move a WordPress website to a different host.

  1. Download all of the site files from the old host
  2. Export the entire database WordPress is using. If you’re not sure how to do that, there are instructions here.
  3. If there are existing files on the new host, back them up by downloading them. Do the same for any databases on the new host.
  4. Upload the site files from the old host to the new one.
  5. Create a new database on the new host. Each host is different, but you’ll have to create a database, a database user, and then give the database user all privileges on the new database.
  6. Import the database from the old host to the new database.
  7. Change the wp-config.php file info to the new database name, host, username, and password.

Some Things to Consider:

  • Most hosts keep the database host as localhost but not all of them. If you’re not sure what your host is, you should contact the new host’s support.
  • This is just moving WordPress to a new sever; I assume you’ve already pointed the domain. If you’re changing domains, you will also have to change all of the domain references in the WordPress database, most notably in the wp_options table (there are two references there). If you don’t change the wp_options table, your site will not work. The best way to change all of the references (most of which being in the posts table) is probably to do a Find/Replace on the .sql file in your favorite text editor after you complete step 2.
  • If you’re moving a WordPress MU/Multisite install, you will also have to configure the sever to handle subdomains. The codex has instructions on how to do that here.

Quick Tip: Get a Family Cell Phone Plan to Save Money

I was talking to a friend yesterday who told me his parents booted him and his brother off their family plan and set them each up with their own, and how much more expensive it is. Let’s look at some numbers. I am on a family plan so I pay: $10 for my line + $10 for unlimited texting + $3.50 for visual voicemail (which I need to cancel) + $30 for the data plan. Thats $53.50. Assuming he is doing the minimum number of minutes, with text, and data (he’s getting the Droid 2), his plan looks like this: $60 for talk and text + $30 for data. That’s $90. Of-course, with Family Plan with his brother, his plan would look like this:

$100 for talk and text + $30(x2) for their data plans = $160 or $80/person. $10. Big Whoop. However, if you bump it up to the next plan for each person, it would be $110 vs $90. $20/month saved. Close to (essentially) a free data plan. If they add one more person to the plan, it would be $170/mo ($10 for the extra line), which divided by 3 is $56.60 per person. Plus, monthly charge savings tend to add up!

Seems like a no brainer at that rate. You will save a good amount of money by playing your cards right with a family plan.*

*note: These numbers are using Verizon Wireless’s plans. Results from other providers may vary.

Quick Tip: User Level Themes for Client Site Reviews in WordPress

Recently I launched a couple of websites using WordPress and instead of using a temp directory for testing/client review, I used a plugin & theme instead. Using this technique I didn’t have to worry about moving directories, changing the WordPress directory/blog URLs,  or checking image sources in posts. Here’s how I did it.

Quick Tip: Facebook Privacy Settings

Facebook, at their annual F8 Conference in San Fransisco, announced that they were expanding the reach of social networking to make it easier for 3rd party sites to access your information on Facebook. This sounds awesomely wonderful if you don’t care about the info you put online. A possible plus is full integration between your likes and related sites. Maybe you “Like” a director on Facebook, so IMDB recognizes it and changes it’s homepage to some of his upcoming work for you. However, you may also see that this is big brother horrifying. It’s also opt-out, not in. So today’s Quick Tip is how to opt out.