This is a guide on backing up your WordPress posts and pages to a GitHub repository. This is great for bloggers who either want a version controlled record of their posts and pages, or for bloggers in the tech space who would like to use GitHub for community feedback on their website’s content.

KeyDigital WordPress to GitHub Backup GuideContents

Installing GitHub Sync WordPress Plugin

To sync WordPress data to GitHub and vice versa typically would require a custom solution, however thanks to the open source community there is a plugin available to assist us with this. The GitHub Sync Plugin for WordPress can be downloaded directly in the Plugins section of WordPress or can be manually installed by downloading it from WordPress.org.

This plugin is open source, and is available for anyone to review or contribute to here on GitHub.

Once the plugin is installed, there will be a settings page available in Settings > GitHub Sync. This is where GitHub token will be added to enable syncing.

Setting up a GitHub Repository

A GitHub repository is where code is typically stored by developers, however it is great for keep version controlled copies of content as well. To create a repository, a GitHub account is necessary. Once logged in, click the plus in the top right corner of the GitHub dashboard to go to the new repository page.

Once on this page, choose a name for your repository, in my case posts and then enable the Initialize this repository with a README option. The GitHub Sync plugin requires at least one commit (or entry) in the repository to be able to sync automatically do it. By enabling the README, a README markdown file will be automatically created, fulfilling this requirement.

Lastly, the repository can be public or private. In terms of syncing functionality it does not matter, it will completely be up the your preference. However, for the syncing functionality to work with private repositories, more permissions have to be given to the Oauth Token responsible for syncing.

Your repository setup screen should look like the screenshot below.

Once your repository is created, please take the full repository name in the [OWNER]/[REPOSITORY] format and enter it into the Repository field of the Settings > GitHub Sync page in your WordPress dashboard. For example, my repository name is keydigital-inc/posts.

Creating an Oauth Token

To create a new Oauth Token, visit this GitHub page and add a note that corresponds to the blog being backed up. Then select the scopes that apply to your repository.

Public Repository Scopes

keydigital-wordpress-to-github-backup-guide-oath-public-repo-token

Private Repository Scopes

keydigital-wordpress-to-github-backup-guide-oath-private-repo-token

After creating the token, there will be a page that shows all token already created for your account. Please copy this code and paste it into the Oauth Token section of the Settings > GitHub Sync page in your WordPress dashboard.

Setting up a Webhook

To create a webhook, visit your repository page on GitHub, click Settings and then Webhooks in the settings’ page sidebar. This will bring up the Webhooks page where you can choose to create a new one.

First, fill the Payload URL with the Webhook Callback URL listed in the GitHub Sync settings page in WordPress. Next change the content-type to application/json. Lastly, choose a Secret that is a secure password and copy it into the Webhook Secret field in the WordPress Sync settings page.

Your Webhook creation page should look like below.

Now click the Add Webhook button and you are set!

Verifying the Sync Works

Once all the fields in the WordPress Sync settings page are filled and saved, you can click the Export to GitHub link. If your repo never updates with the synced data, refresh the WordPress Sync settings page and there should be an error at the top. Verify that all the fields are entered correctly.

In the case that your posts and pages sync correctly, congratulations! You now have a working backup method for your content to GitHub. Now, if you make edits within GitHub to your posts, you can use the Import from GitHub link to bring those changes back into your WordPress blog.

Note: This will only pull updated posts that are merged or edited within the master branch of the GitHub repo.