Thus far, my move to WordPress has been an adventure. Here’s a few lessons learned.
First off, I was very excited about the features of WordPress. I was really excited, most specifically, about the API, and about the rich text WYSIWYG of the backend. I’ve done a lot of work on Small Axe’s backend, but it’s still nothing compared to WordPress.
When I imported my stuff, it worked well, but the “slugs” — or URL-friendly post titles — did not convert properly. They converted as WordPress friendly, properly escaped slugs. The problem was, my slugs needed to stay intact, because I didn’t want all old links to break.
Understanding the way WordPress functions is really tough for a WP newbie, because the code is so spread out, yet compact, voluminous, yet digestible. Start with index.php, onto wp-blog-header.php, into wp-settings.php, and then you find the massive list of files in the wp-includes directory. You’ll dig all over trying to find files to find includes in includes in includes. I finally found a great article that tries to explain the WordPress slug architecture. It’s fairly complex. Much of it lives in/wp-includes/query.php. However, my problem was very specific.
Many of my post slugs had periods in them. The period does not interfere with the URL, but WordPress doesn’t like them, and somewhere in the massive beast. So I had to find the page that “gets” posts. Lo and behold, there is a function called “get_posts” that lives in /wp-includes/query.php. I kept poking around. Like anyone who keeps digging, eventually, you’ll find yourself in wp-includes/formatting.php. And there it is.
Slug posts get sanitized – like everything, virtually all input is strictly sanitized – by a function called sanitize_title_with_dashes(). This function generates the slug. In order to include dots in your slug titles, just replace lines 366 and 267 (on WordPress 2.6.0) with this:
$title = preg_replace('/&+?;/', '', $title); // kill entities $title = preg_replace('/[^%a-z0-9 _.-]/', '', $title);
Then your slug titles will not strip periods. Of course, I don’t recommend you actually use periods, I just wanted them to work when fetching old posts created before I knew any better.
After that adventure, I have to tell you, I’m really loving WordPress. There are some incredible plugins that have done some amazing functionality extension for me. So far, so good.