42

I would like to make my WordPress blog installed on Localhost to push into GitHub and run that on GitHub as a static page. Can I do it, and if yes please give me a detailed answer with the steps and problems involved?

I don't care if my page is static, but will I be able to host it on GitHub pages?

7 Answers 7

27

This website gives a good answer on how to do this: https://www.hywel.me/static/site/wordpress/2016/07/17/fast-free-static-website-with-wordpress-and-github-pages.html

In short:

  1. Set-up GitHub pages.
  2. Install Simply static plugin into WordPress.
  3. Push the export from the plug-in back to your git repository and you are done!
6
  • How is the content updated in this setup? Can users go to the admin page or will they need to clone the repo to their local machine, update the content , then push to origin?
    – Edward
    Commented Jun 21, 2017 at 17:58
  • 1
    You just need to install the WordPress plugin either locally (free) or on a server. Next you let it generate a zip files with all static files. Unzip it, commit it to git and push to the appropriate GitHub branch. works as expected if you follow the guide.Keep in mind that dynamic non JavaScript stuff like search will stop working. If you want to update do your updates in the WordPress install and just do another export and repeat the steps.you can just overwrite the old files and git detects the changes.
    – Christoph
    Commented Jun 23, 2017 at 8:19
  • Yes, but I'm talking about a system where a user can only use a wysiwyg. They aren't going to set up a local wordpress install and set up git.
    – Edward
    Commented Jun 28, 2017 at 20:54
  • If you install wordpress on a server you can maybe create a bashscript and a chronjob to automatically unarchive the export, replace the folder and commit and push to git. That way you can say it syncs every hour(?) and they don't need to setup anything.
    – Christoph
    Commented Jun 29, 2017 at 9:08
  • Simply Static doesn't support chron jobs, though. Do you have an example/docs on this bashscript? I'm not a backend person so I'd need the steps on how to do this. Anything short of that is just rest of the f-ing owl to me
    – Edward
    Commented Jun 30, 2017 at 14:42
13

You can't. You would use WordPress if you want a dynamic page - that is the whole point of using it. You could of course grab the html generated by WordPress and push that to your GitHub, but that I think that would be a lot of manual work.

You could try a static page generator, i.e. https://github.com/jekyll/jekyll

2
  • 4
    PS. You could use a tool to grab all source code for each page (SiteSucker for OS X is really good if you're on a mac) and then do a multi-file search and replace to swap all links to your github address. Not too much manual work really :) Commented Oct 9, 2015 at 6:43
  • 4
    For the top-voted answer, this is quite misleading. As the author of the WP plugin linked in the other answer here, both it and another popular WP to static HTML export plugin exist to do just that. My plugin will also automate the deploy to services including GitHub Pages, so it's a one-click process, much easier than using SiteSucker, HTTrack or such to manual crawl and then push to GH: wordpress.org/plugins/static-html-output-plugin
    – ljs.dev
    Commented Jun 25, 2018 at 6:01
7

If you absolutely can't switch from wordpress, but absolutely need to host on github pages, then your only option is probably to look into some wordpress plugin that will take your entire site and spit out a static website (sort of like jekyll, but for wordpress specifically).

edit: There actually is such a plugin: https://wordpress.org/plugins/static-html-output-plugin/

I just tested it out on a brand new WP installation and it seems to work alright, but a few things seem not to work.

0
4

Unfortunately, and simply you can't do this as WordPress is a WebApp, that is, requires a database. Sorry to be the bringer of bad news.

If you are considering an alternative, consider the following static site generators which can be hosted from GitHub Pages:

0
4

You can migrate fromwordpress to jekyll static site generator, the one powering github pages.

You will find migration documentation on the jekyll site.

3

No, for that you would need:

  • Go to Github, create a new repository with this convention: .github.io.
    For clarity sake, my repo would be andy4thehuynh.github.io.
  • Also, create a local instance of a hugo repo.
    Cd into an empty directory on your local machine and execute hugo new site ./.
    Initialize a git repo with git init and add your remote git remote add origin [email protected]:<your_handle>/<your_handle>.github.io.git.
    Cool, we have a fresh blog repo.
  • Let’s add a test post; execute hugo new post/test.md and echo 'Your live on Github Pages' >> ./content/post/test.md.
    Set the draft flag to true to make sure your post renders.
  • Tell Hugo to build your site by running hugo.
    Your public directory should be populated with a freshly generated site. Awesome!
  • Here comes the sauce; perform a echo 'public' >> .gitignore. Now, Git will have no idea of your public directory (your compiled public content users will view in a browser). You’ll see why quickly.
  • Switch out of the master branch with git checkout -b source. We do this since GH pages doesn’t care about our source code (aka our source branch). It only cares about the public content.
  • Add and commit your source changes. Do a git add -A and git commit -m 'Initial Commit'. Push your changes with git push origin source.
  • Lastly, cd into your public folder. Notice Git is not keeping track of changes here. This was for intended purposes. Do a git init, git add -A and git commit -m 'Initial commit'. Push your changes with git push origin master.

Open a browser to your repo named .github.io and switch between your source and master branches.
All your compiled content should be in your master branch.
GH pages will see that and render it at <your_handle>.github.io.
You’ll write your drafts in your source branch. Compile it with the hugo command. When your happy with your compiled changes, push your public folder and become a rock star.

0
1

Yes you can and it's extremely easy. Benefits:

  1. You can use as always the wp-adnin features
  2. Sites will be host by GitHub pages (extremely fast)
  3. As the site is static you will not have security issues unless you do things badly.

Steps:

  1. Create a complete wordpress site on subdomain, example: static.mydomain.com
  2. Install Simply Static Pro version that allows you to easily generate a static site and automatically upload it to GitHub (just follow documentation)
  3. Enjoy your free hosted and extremely fast static site.

Bonus:

  1. Use wp-rocket optimizations. When the static site is created it will benefit from those.

  2. As there is no databases, plugin forms ninja Forms will not work so use the ones accepted by the simply static plugin or third party like Typeform or google forms.

  3. For security purpose configure your server to only accept you IP connection to static.mydomain.com this will increase your security and avoid google from indexing this subdomain.

Not the answer you're looking for? Browse other questions tagged or ask your own question.