Can I host my wordpress blog on github pages as a static webpage

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?

Related posts

7 comments

  1. 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. 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.

  3. 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:

  4. 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 git@github.com:<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.

  5. 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.

Comments are closed.