How to Import Squarespace into WordPress

Recently I had to convert an entire squarespace website to wordpress. There is no official way to do this and some pages do require custom scripts/scrapers however it is possible to convert the squarespace posts easily.

New WordPress plugin and how-to video

Update: I have a written a WP plugin to do this, click here to view the squarespace to wordpress plugin post. There is also an instructional video.

Otherwise, you can use the more advanced method, outlined below.

First, login to your square space website, click on structure > configure this page. Go down to Data Export and Export Blog Data to get a backup of your posts. This only works for squarespace posts not other content.

Next go to your wordpress installation, click Tools > Import. Install the Movable Type and TypePad post importer plugin. Now run this plugin on your exported squarespace posts and they will import into wordpress. It would be wise to create a new user when importing these posts so they are easy to identify.

So now that you have your squarespace posts imported into wordpress, you may have noticed all of the images are referring to square space still. You will see html code such as:

What we need to do is run a script that will go through our imported posts, download the squarespace images, rename them, upload them into wordpress, add them as attachments to the posts they belong to and change the html to reflect this.

Sounds complicated doesn’t it? Click below to download my quick solution:

Download the source

The tools run on linux/unix command line, it uses wget to download the file so you must have that installed. Explanation on how to install wget and run php scripts on the command line is beyond the scope of this post. Please do this on a local/backup copy of wordpress unless you are sure you know what you are doing and as always, make a backup first. This script also uses the php function shell_exec to run wget, some shared hosts may disable this, again it’s better to do this on a local development environment.

Open config.php and set these constants. The squarespace prefix is important for use in a later script. The download path (./images in the current directory by default) must have write permissions for your user or just chmod 777.

Execute the script on the command line:

The terminal output looks like this:

This script is…

  1. Looping over your posts and finding squarespace images
  2. Downloading the squarespace images to the directory YOUR_DOWNLOAD_PATH
  3. Renaming them based off the post title slug
  4. Replacing the html of the wordpress post to reference this new link

So now we have downloaded the squarespace images and changed the html but we are not done yet. For starters we need to import those images into wordpress and then change the image src again to match the fully qualified wordpress url. The reason we did not do this in the last script is a perfectly good plugin already exists to do this upload. Install Add From Server plugin into your wordpress install: http://wordpress.org/extend/plugins/add-from-server/

Once Add from server is installed use it to upload all of the images downloaded from squarespace. It’s under the media tab in the wordpress admin. You will need to copy your downloaded images folder to wp-content.

Now that Add from server has uploaded your squarespace images and created the attachment data, we are going to link these attachments with their posts and update the image srcs to reflect the attachment urls.

Simply run

This script:

  1. Loops through your wordpress posts
  2. Find all images in a post
  3. Checks to see if the image begins with your SQUARESPACE_PREFIX
  4. If it does, it associates the attachment ID with the current post
  5. Sets the first matched image to your featured image
  6. Updates the image URL to be the fully qualified wordpress attachment URL

It looks like this:

So there you have it, you’ve imported squarespace posts with images too! Hopefully this will be helpful to some people.

So now, in your wordpress post content, instead of the squarespace image links you will see:

You could write other script/conversion tools to cleanup the remaining squarespace html. I had to write several mini scripts such as the ones above to import things like squarespace galleries and other custom content types.

If enough people need this, I could start writing a proper wordpress import plugin, or at least combine the three steps into one script. This approach could more or less be used for converting any site to wordpress that doesn’t have an official importer, so feel free to modify it.

Download the source

Update: There is now a wordpress plugin for this: click here to download the squarespace to wordpress plugin.

,

28 thoughts on “How to Import Squarespace into WordPress

  • Greg,

    Nice job programming the process. Between your solution and mine (http://robpickering.com/2010/07/moving-from-squarespace-to-wordpress-3) folks should have no issues moving off of SquareSpace and onto WordPress.

    Nice job!

    -Rob

  • Diane Holmes says:

    Thanks for posting this. 🙂 This is REALLY excellent (and awfully nice of you).

  • Federico says:

    Wow! I will give this a try!
    Thank you so much!

  • Federico says:

    Hi Greg,
    I’m trying this on my mac using mamp.
    I get a database error when running the script.
    How does the script authenticate in wordpress and connects to the database?
    Also, is it failing because the mysql port in Mamp is 8889 and Apache runs on port 8888?
    Thanks!
    Federico

  • Federico says:

    OK Making progress.
    I have my wordpress site install locally on MAMP.
    So I realized I had to run my php command from the MAMP environment, so:
    /Applications/MAMP/bin/php/php5.3.6/bin/php download_images.php in my case.
    The download images worked like a charm!
    Unfortunately the second script, set_attachments.php is not working for me….
    I run it, it waits a few seconds and then ends without any error, but it never does what is supposed to do.
    Any ideas?
    Thanks again!
    Federico

    • Greg Freeman says:

      When you ran the first script, did it modify your posts? changing the old squarespace urls to the new renamed file name? Did you upload your downloaded images using the ‘add from server’ plugin? The 2nd script updates your posts for the 2nd time, changing the partial urls set my script 1 to be the full attachment url – This will only work if you uploaded the attachments using ‘add from server’ (Otherwise they won’t exist).

  • Federico says:

    I think the problem lays in the download_images.php script:
    I downloads and renames the images successfully, but fails to change the old URL’s in the individual posts.
    I went back and check and in the posts everything still point to the Squarespace URL’s

    • Greg Freeman says:

      It sounds like you didn’t import your downloaded images using the add from server plugin so when you run the 2nd script, it is unable to update the links because they are not in the media library. – Greg

  • Federico says:

    I did import them using the add form server plugin.
    This what happened:
    Ran the first script.
    The images got downloaded and renamed correctly, but, in the first script there are a few lines of code that should also modify the URL’s pointing to the squarespace images in the post html.
    After running the first script, if I check a random post, I can see that the html doesn’t get modified, the URL’s in there are still the squarespace ones…
    You mention in the article that after running the first script things will look like this:

    In my case that doesn’t happen, so something goes wrong…
    Fede

  • Federico says:

    oops, can’t quote code, look at your article where you write:
    “So now, in your wordpress post content, instead of the squarespace image links you will see:”
    You’re showing a post after running the script with img src’s modified, that doesn’t happen to me, I still see al the original src pointing to squarespace

    • Greg Freeman says:

      There must be differences in your original squarespace page code that differs to mine if it is not replacing the code in the post content. I just used this to convert a rather large site over so it does work and has for some others. I Recommend that you inspect the base code I provided and modify it for your needs. I can’t help you without seeing your specific use-case.

      On line 68 of download-images, it does a basic str_replace to replace the original squarespace url with the newly formed image name before saving the wordpress post. If this is not working for you then you’re squarespace urls could be different in some way. You could always run a debugger to see what it is trying to replace at your test for your test case.

      Feel free to provide me with a sql dump of your database and I see if I can reproduce your problem. You can send the link in the contact form above.

  • Federico says:

    I sent you a link to a text file in my dropbox, just a few lines showing you the format of the Squarespace URL’s in one post.
    Thx!

  • Federico says:

    GOT IT!
    Different Squarespace URL formats!
    In your case images are linked using a full url:
    yoursite slash storage slash images slash image name
    In my case:
    slash storage slash images slash image name
    I’ve added a line of code that strips my domain from the variable src e voila’

    Thank you thank you thank you for your help!

  • Does this work on hosted WordPress.com? Trying to look before I leap. If not, I’ll likely use another hosting provider – not sure WP.com gives access to run *nix commands.

  • Prashant says:

    Thanks so much for this post Greg. I ran into a small issue when trying to execute the download_images.php script. It is complaining about wp-load.php:

    “Failed opening required ‘http://www.careerify.info/wp-load.php’ (include_path=’.:’)”

    I ensured that this is where the file is but it cannot seem to open it. Is there something I am missing here? Thanks in advance!

    • Greg Freeman says:

      It should be a path to wp-load.php not a url.

      • Prashant says:

        I would like to point it to the root directory of my website (www.careerify.info) as this is where WP was installed.

        • Greg Freeman says:

          Hi,

          Your url may be careerify.info but your path would be something in the form of /home/careerify/public_html/wp-load.php.

          You could ask your webhost for the path to your home directory. In the example scripts I use .. and . to denote a path relative to the current script. There is also a plugin: http://www.gregfreeman.io/2012/squarespace-to-wordpress-plugin/

          • Prashant says:

            Thanks Greg, I’ll look into this with GoDaddy. Much appreciated!

          • Prashant says:

            This is probably obvious but I guess I need to upload the script you provided to my site and run the php script from there right?

          • Prashant says:

            I got everything working. This was a fantastic tutorial. I had to modify the $src variable around line 61 to remove the base url of my website from the source since the source according to squarespace was a relative url. The following worked for me and may help someone else in the future (insert on the line before the $my_post[‘post_content’] = str_replace(…)):
            $src = str_replace(“http://www.baseurl.com”,””,$src);

  • Jay says:

    I’m new to SquareSpace, and have attempted to run this script to migrate my SquareSpace site back to something more familiar: WordPress.

    I am not however, having any luck getting the script to run (or at least output any information) to show that it’s in fact grabbing the images.

     

    My question is: does this script still work with the latest version of SquareSpace?

  • Jay Doubleu says:

    Does this process work with the latest iteration of squarespace? I ‘ve attempted to run the scripts via the command line, and they don’t appear to do anything at all. I’ve ran them verbose as well, they just run once and fail.

    Your insights are appreciate.

  • Candace says:

    Hi! I followed these instructions and nothing transferred over. I can’t imagine manually inputting every single post over again but its feeling like that is whats next.

Leave a Reply to Federico Cancel reply

Your email address will not be published. Required fields are marked *