{"id":3212,"date":"2013-10-04T14:16:59","date_gmt":"2013-10-04T14:16:59","guid":{"rendered":"http:\/\/dev.adambowie.com\/?p=3212"},"modified":"2013-10-04T14:16:59","modified_gmt":"2013-10-04T14:16:59","slug":"migrating-from-movable-type-to-wordpress","status":"publish","type":"post","link":"https:\/\/dev.adambowie.com\/blog\/2013\/10\/migrating-from-movable-type-to-wordpress\/","title":{"rendered":"Migrating from Movable Type to WordPress"},"content":{"rendered":"<p>For a long time now, I\u2019ve been very frustrated with the blogging platform I\u2019ve used since I started properly blogging here back in 2002. At the time, Movable Type seemed to be the \u201cgo to\u201d platform. And it was fine for many years. <\/p>\n<p>I\u2019m in no way a web-developer but a lot of Googling meant that I learnt at least a tiny bit about installing a blog on a server, and the intricacies of MySQL, PHP and so on.<\/p>\n<p>But more recently, Movable Type has been falling by the wayside, and in their latest iteration, they\u2019ve essentially abandoned the private blogger. <\/p>\n<p>Now I know that WordPress isn\u2019t perfect, but there\u2019s a much bigger community developing for it these days than anywhere else. And I certainly didn\u2019t want the simplicity of seemingly popular platforms of today like Tumblr.<\/p>\n<p>So I\u2019ve finally bitten the bullet, and moved this blog over to WordPress.<\/p>\n<p>What follows is probably going to be exceedingly dull to 99% of people who read this blog. So feel free to skip over it. But for the other 1%, or those who encountered similar problems to me, and found this site via Google, there may be the odd helpful hint here.<\/p>\n<p>I was very nervous. <\/p>\n<p>If you look around the web, you\u2019ll find many different guides to making the change. I did a lot of searching before I started, and as I encountered problems along the way. Surely enough people had trodden this route before and published their solutions online?<\/p>\n<p>But they all seemed to have slightly different case usages to my own. Aside from that, many of the techniques and plugins listed are now outdated or have disappeared from sites. More than once I read about an ace plugin that would solve a problem, only to find that it had disappeared, or didn&#8217;t work with more recent versions of WordPress. <\/p>\n<p>So I\u2019ll document here what I went through to get WordPress installed and everything moved over.<\/p>\n<p><B>1. Install WordPress<\/B><\/p>\n<p>My Movable Type installation was in <code>www.adambowie\/weblog<\/code>. A simple redirect took people who visited <code>www.adambowie.com<\/code> to that sub-directory. While I probably could have installed WordPress into that folder, I didn\u2019t. Instead, I installed it to <code>www.adambowie.com<\/code>. Note the subtle difference!<\/p>\n<p>I actually installed WordPress some time ago, and there are plenty of places online to step you through that process if you run into trouble.<\/p>\n<p>Once installed, I spent a while tinkering with a standard template (Twenty Eleven in my instance) making it similar &#8211; but different &#8211; to my old blog. That also meant learning about things like Child Templates, and doing a lot of Googling about CSS to discover how to make changes that I wanted.<\/p>\n<p>I also wanted to find some decent methods for commenting, which was always one of the biggest issues I had with Movable Type. In particular, I wanted to include social media commenting, even though I know that quite a lot of people don\u2019t like using it. To be honest, real comments are becoming few and far between with more commentary happening on Twitter or Facebook when I post links to new blogs. In my case, I\u2019ve only switched on Google and Twitter since I don\u2019t really like using Facebook. We\u2019ll see how comment spam goes.<\/p>\n<p>Once I was happy with my new look &#8211; and I suspect that it\u2019s a look that will evolve, since it still looks a bit too &#8220;WordPress-y&#8221; &#8211; I moved on to the next stage.<\/p>\n<p><B>2. Export Movable Type<\/B><\/p>\n<p>There&#8217;s a pretty decent explanation of the whole  migration process on the <a href=\"http:\/\/codex.wordpress.org\/Importing_from_Movable_Type_to_WordPress\">WordPress Codex<\/a>, but it didn&#8217;t get me the whole way there.<\/p>\n<p>Exporting was perhaps the most painless part of the process. I was coming from Movable Type 5.2.2 and it was just a question of going to <strong>Tools > Export Entries<\/strong>. This produces a text file with most of the important stuff from your old blog.<\/p>\n<p><B>3. Import Into WordPress<\/B><\/p>\n<p>Again, a simple stage. Go to <strong>Tools > Import<\/strong> and select <strong>Movable Type and TypePad<\/strong>. At this point you have to install and activate a WordPress plugin to allow this to happen.<\/p>\n<p>I had just over 3,000 entries with associated comments, and it didn\u2019t take that long to run its course. I only had one user and I had to tie that up with a user in WordPress. Just step through the process as prompted.<\/p>\n<p>The only significant issue I had at this point was that line returns seemed to be broken. In Movable Type I tended to put two line returns between paragraphs and the software seemed to handle that. One way or another, in the export\/import process, that broke. And I don\u2019t seem to be the only one who had that problem. I ended up fixing mine by using a bit of CSS that I added to my Child Theme:<\/p>\n<blockquote><p><code>br {<br \/>\n   display: block;<br \/>\n   margin: 10px 0;<br \/>\n   content: \" \";<br \/>\n}<\/code><\/p><\/blockquote>\n<p>That seems to be a cross-browser solution with Chome requiring the \u201ccontent\u201d addition.<\/p>\n<p>It\u2019s a workaround, but leaves me happy with the text layout.<\/p>\n<p>Given that I already had a redirect from <code>www.adambowie.com<\/code> to <code>www.adambowie.com\/weblog<\/code> it might seem to be just as simple as amending that to point at <code>www.adambowie.com<\/code> and I\u2019d be done. But that ignores by far the most fiddly part of the process&#8230;<\/p>\n<p><B>4. Redirecting Permalinks<\/B><\/p>\n<p>One way or another, I have some decent Google-juice on this site, and there are no doubt all kinds of historic links around the place. So I wanted to ensure that both internal and external links continued to work.<\/p>\n<p>Now there are lots of ways to do this using various techniques. I had some complications in that my old Movable Type structure used a numerical permalink in a single folder, while I wanted WordPress to use a better <i>date\/description<\/I> structure.<\/p>\n<p>So for example my review of the new Google Nexus 7 used to reside at:<\/p>\n<p><code>www.adambowie.com\/weblog\/archive\/003405.html<\/code><\/p>\n<p>Whereas on import into WordPress it could now be found at:<\/p>\n<p><code>www.adambowie.com\/2013\/10\/short_nexus_7_2<\/code><\/p>\n<p>Following the WordPress <A HREF=\u201dhttp:\/\/codex.wordpress.org\/Importing_from_Movable_Type_to_WordPress#Using_.htaccess_for_redirection\u201d>instructions<\/A>, and because my old Movable Type blog had padding in the numbers, I ended up creating the following new Index Template within Movable Type:<\/p>\n<blockquote><p><code><br \/>\n&lt;?php<br \/>\nrequire('wp-config.php');<br \/>\nheader('Content-type: text\/plain');<br \/>\n?><br \/>\n<MTEntries lastn=\"999999\"><br \/>\nRedirect Permanent \/archives\/<$MTEntryID pad=\"1\"$>.html http:\/\/dev.adambowie.com\/archives\/<$MTArchiveDate format=\"%Y\/%m\/%d\"$>\/<br \/>\n   &lt;?php echo sanitize_title(\"<$MTEntryTitle$>\"); ?><br \/>\n<\/MTEntries><\/code><\/p><\/blockquote>\n<p>I must admit that when I did this, I didn\u2019t really understand what I was doing, because my knowledge of PHP is close to zero. Because it was in my old blog\u2019s location, I worried about the \u201crequire\u201d code and relative paths. But I should have just followed instructions. WordPress tells you to send the output to a file called <code>redirect.php<\/code> in the WordPress root directory. So in my instance it meant sending it to <code>..\/blog\/redirect.php<\/code> (from <code>\/weblog<\/code> where the Movable Type installation was).<\/p>\n<p>So I created a new &#8220;index&#8221; by publishing this template.<\/p>\n<p>The bit that <I>wasn\u2019t<\/I> explicitly explained to this fool was that you then had to <I>run<\/I> that file in it\u2019s new home. i.e. visit <code>\/blog\/redirect.php<\/code> in my browser.<\/p>\n<p>But this did introduce a problem. I got repeated errors because I\u2019d used inverted commas in my blog headings in Movable Type. These had been dutifully output by the Movable Type template, but the surplus inverted commas broke the PHP. So I dutifully edited <code>redirect.php<\/code> textfile to remove them all. At first it was just searching for <code>\u201d\u201d<\/code> but that only found subjects where I\u2019d used inverted commas at the beginning or the end of the subject. Fortunately, the PHP error code gave a line number, and you can track that down in Notepad (which I was using) as long as you turn Word Wrap off. Other text editors are available.<\/p>\n<p>Finally, having done all that, the file ran, although I still got a header error. This may have been down to some kind of surplus white space. But I couldn\u2019t fix that. However I now had the output I needed\u2026 sort of.<\/p>\n<p>I copied and pasted the output of my browser into Word, and put some carriage returns back into it using a find\/replace with the paragraph character. And I obviously removed the errors at the top.<\/p>\n<p>I had a list of 3,000 or so lines looking a bit like this:<\/p>\n<p><code>Redirect Permanent \/archives\/003405.html http:\/\/dev.adambowie.com\/archives\/2013\/10\/01\/ short-nexus-7-2013-review<\/code><\/p>\n<p>Theoretically, I just needed to paste this into an <code>.htaccess<\/code> file and I was home and dry. But there are a few things wrong with this code, and I\u2019ll explain them all now, although some took me ages to work them all out. <\/p>\n<p>First of all, I believe that <code>Redirect Permanent<\/code> is case sensitive, so it should be <code>Redirect permanent<\/code> although I ended up using <code>Redirect 301<\/code>. <\/p>\n<p>Secondly, and very specifically to me, it took me ages to spot a random \u201cs\u201d in \u201carchives\u201d. It should have been &#8220;archive&#8221; in Movable Type and there is no need for &#8220;archives&#8221; at all in my Movable Type structure!<\/p>\n<p>Thirdly, you\u2019ll notice that there\u2019s a space that\u2019s unnecessary after the date. <\/p>\n<p>Fourthly, the format has too much date info. I only need year and month &#8211; not day as well. I don&#8217;t blog so much that I need anything beyond a year and month structure. I edited this out by using Excel&#8217;s text to columns functionality to get the &#8220;day&#8221; field into it&#8217;s own column which I could remove.<\/p>\n<p>Fifthly, and perhaps most frustratingly, the <code>santize_title<\/code> PHP command didn\u2019t do what WordPress had done with my blog item titles on import. It used dashes instead of underscores, and on import, WordPress had shortened URLs to the first 15 characters. <\/p>\n<p>I could sort out all those things in Excel with some use of the data functions and so on, alongside CONCATENATE to stitch the bits together. But unfortunately, there were still issues with page names where similar blog entries had meant WordPress had added numbers to keep unique page references. <\/p>\n<p>In the end I used another PHP script I found <a href=\"http:\/\/stackoverflow.com\/questions\/3464701\/export-list-of-pretty-permalinks-and-post-title\">online<\/a> to export the true names of each page from WordPress. I named this <code>export_names.php<\/code> and imported the results into Excel where I tied them up with the Movable Type permalinks. <\/p>\n<p>Here\u2019s the script:<\/p>\n<blockquote><p><code>&lt;?php<\/p>\n<p>include \"wp-load.php\";<\/p>\n<p>$posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');<br \/>\n$posts = $posts->posts;<br \/>\n\/*<br \/>\nglobal $wpdb;<br \/>\n$posts = $wpdb->get_results(\"<br \/>\n    SELECT ID,post_type,post_title<br \/>\n    FROM {$wpdb->posts}<br \/>\n    WHERE post_status<>'auto-draft' AND post_type NOT IN ('revision','nav_menu_item')<br \/>\n\");<br \/>\n*\/<\/p>\n<p>header('Content-type:text\/plain');<br \/>\nforeach($posts as $post) {<br \/>\n    switch ($post->post_type) {<br \/>\n        case 'revision':<br \/>\n        case 'nav_menu_item':<br \/>\n            break;<br \/>\n        case 'page':<br \/>\n            $permalink = get_page_link($post->ID);<br \/>\n            break;<br \/>\n        case 'post':<br \/>\n            $permalink = get_permalink($post->ID);<br \/>\n            break;<br \/>\n        case 'attachment':<br \/>\n            $permalink = get_attachment_link($post->ID);<br \/>\n            break;<br \/>\n        default:<br \/>\n            $permalink = get_post_permalink($post->ID);<br \/>\n            break;<br \/>\n    }<br \/>\n    echo \"\\n{$post->post_type}\\t{$permalink}\\t{$post->post_title}\";<br \/>\n}<\/code><\/p><\/blockquote>\n<p>Finally, I was left with some text that I could place into a file in Notepad and create an <code>.htaccess<\/code> file that I placed in the root of my blog. Here\u2019s an example line:<\/p>\n<p><code>Redirect 301 \/weblog\/archive\/003405.html http:\/\/dev.adambowie.com\/2013\/10\/short_nexus_7_2\/<\/code><\/p>\n<p>As I understand it, using a 301 redirect tells search engines that the change is permanent, and they\u2019ll update their records to crawl over the new URLs.<\/p>\n<p>Finally, I had to fix my RSS feeds since I suspect, even with the death of Google Reader, feed-readers are the main way that people discover I\u2019ve published new blog entries. That was a straightforward process of adding some extra lines to the <code>.htaccess<\/code> file redirecting my old XML RSS feeds (RSS 2.0 and Atom in my case) to the relevant <a href=\"http:\/\/codex.wordpress.org\/WordPress_Feeds#Finding_Your_Feed_URL\">WordPress feeds<\/a>.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Could there still be problems buried in some old entries? Almost certainly. But hopefully most stuff is viewable, and search engines will find their new homes. If something does look badly broken, do let me know!<\/p>\n<p>One final WordPress problem I did have to overcome was with my photos based on html embedded code from Flickr. While the photos displayed fine on large screens, if the display was narrow &#8211; e.g. a mobile screen &#8211; the Twenty Eleven WordPress theme was resizing the width of the photos accordingly, but leaving the height alone. That made all the photos appear squashed.<\/p>\n<p>The solution is the CSS code from <A HREF=\u201dhttp:\/\/wordpress.stackexchange.com\/questions\/84292\/twenty-eleven-theme-and-automatic-picture-resizing\u201d>here<\/A>:<\/p>\n<p><code>.entry-content img { max-width: 100%; height: auto; }<\/code><\/p>\n<p>That fixed it!<\/p>\n<p>I hope some of this helps at least somebody out there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a long time now, I\u2019ve been very frustrated with the blogging platform I\u2019ve used since I started properly blogging here back in 2002. At the time, Movable Type seemed to be the \u201cgo to\u201d platform. And it was fine for many years. I\u2019m in no way a web-developer but a lot of Googling meant [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8],"tags":[37,39,38],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/posts\/3212"}],"collection":[{"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/comments?post=3212"}],"version-history":[{"count":15,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/posts\/3212\/revisions"}],"predecessor-version":[{"id":3227,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/posts\/3212\/revisions\/3227"}],"wp:attachment":[{"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/media?parent=3212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/categories?post=3212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.adambowie.com\/blog\/wp-json\/wp\/v2\/tags?post=3212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}