Posts Tagged with “code”

Comments Closed

Useful SQL queries for migrating a WordPress database

First, if at all possible, use the WP Migrate DB Pro or BackupBuddy plugins to migrate your WordPress database. The money spent will save yourself a lot of frustration and hair pulling, and hours if not days of cleanup and massaging of the WordPress database.

But if that’s not possible, welcome to my world for the past week. I’ve had to migrate a WordPress database without my favorite migration tools. After scouring the web for tutorials and tips, I’m compiling them here for easy reference.

Gather Your Tools

First thing you need is to get your hands on the following:

1. Database name, prefix, user and password.

You can find these defined in the wp-config.php file. In the following examples, be sure to swap out the database name wordpress and prefix wp_ with the correct values from your situation.

2. Access to phpMyAdmin so that you can interact with the database.

We’ll be running the commands below through the SQL tab in phpMyAdmin.

phpmyadmin-sqlquery

Running SQL queries on your database with phpMyAdmin

You could also connect directly to MySQL through the terminal / shell prompt. Good luck if you don’t have phpMyAdmin.

3. Backup, Backup, Backup

Don’t say I didn’t warn you. Export your untouched database and lock it up. If all goes wrong, restore to this backup.

Change the Site URL

The first thing you would want to do is to change the site URL. You can browse the wp_options table for the siteurl and home options values directly, or you can use this SQL command:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'siteurl' OR option_name = 'home';

Next, you’ll want to replace all instances of oldsiteurl.com in your post’s contents and GUID.

UPDATE wp_posts SET post_content = REPLACE (post_content, '//www.oldsiteurl.com', '//www.newsiteurl.com');
UPDATE wp_posts SET guid = REPLACE (guid, '//www.oldsiteurl.com', '//www.newsiteurl.com');

Read More »

Custom size featured image thumbnail with fallback in WordPress

Occasionally you may need to display featured images in sizes other than WordPress’ default thumbnail, medium and large sizes. That’s quite easily solved with the add_image_size() and the_post_thumbnail() functions. Unfortunately, there are still 2 problems to be solved:

  • Some posts may not have images at all, or the author forgets to attach a featured image
  • Previous posts don’t have featured images

Here’s a solution that 1) resizes the featured image to the right size, 2) uses the first image in the post if a featured image is not set and 3) falls back to a default image if none of the above are true. Read More »

More robust footer widget areas for Headway

I recently got an email from a reader who wanted to know how I implemented my footer widget areas, and seen some similar requests in the Headway forums. With Headway, you can flip your widget areas horizontally to make a widgetized footer but it works best when you only have 3-4 widgets in them. I wanted to have more flexibility and so I injected 3 widget areas into my footer.

Screenshot for posterity, if I ever re-design this blog. Click for full-size image.

I didn’t have time for a full tutorial but hopefully you’ll find these code snippets useful:

blogjunkie.net custom_functions.php for Headway theme

blogjunkie.net custom.css for fat footer widget areas

Solved: Cufon text not refreshing on jQuery UI Tabs

Update: I no longer use Cufon in my projects and prefer @font-face. If you are struggling with Cufon it will actually be faster for you to replace it with @font-face than to figure out your Cufon problems. Start with this tutorial here: The Essential Guide to @font-face

Today I was working on a project that:

  1. Made use of jQuery UI Tabs through the WordPress Post Tabs plugin
  2. Uses custom fonts for the tabs via Cufon
  3. Requires tab font to change color when selected

Read More »

Simple form validation with FBJS on Facebook Page Tabs

Today I was working on a custom Facebook Page which included a sign up form. On the sign up form was a checkbox with an id of confirmoptin that needed to be checked before the form could be submitted: Read More »

Remove Headway update notifications

As you know I’m a big fan of the Headway WordPress theme. So much so I’ve been using it in client projects.

The one (small) drawback is that Headway puts a notice in the Dashboard every time there’s a new version. For certain clients I really don’t want to have anything to do with them after the project, so I would like to disable the notification. Here’s how.

In Headway’s custom_functions.php, simply add this line:

remove_action('admin_notices', 'headway_update_notice');

Solved. No more nagging client asking me what is this “Headway update thing”.