WP-CLI is a developer-friendly way to manage WordPress sites. WP2Static integrates with WP-CLI, adding useful commands to generate and deploy your static site.

WP-CLI commands

Running the command wp wp2static will give you all the avaiable options and is the best way to know which commands are available on your system. WP2Static Add-ons may provide additional commands.

WP-CLI commands will apply to the site relative to the system path you run them from.

Multisite WP2Static WP-CLI commands

When running WordPress in a Network/Multisite setup, add the --url=<url> argument to force the command to be applied to the WordPress site with that Site URL.

WP-CLI examples


Install and activate WP2Static, set options and generate static site Zip archive.

  • wp plugin install --activate static-html-output-plugin
  • wp wp2static options set selected_deployment_option zip
  • wp wp2static options set baseUrl https://mystaticsite.netlify.com
  • wp wp2static generate
  • wp wp2static deploy

A new ZIP archive will be created and path can be retrieved with:

echo "$(cat wp-content/uploads/WP2STATIC-CURRENT-ARCHIVE.txt | sed 's/.$//')".zip

/wpinstallpath/wp-content/uploads/wp-static-html-output-1574438458.zip

Note: the plugin’s slug, as used within the official wp.org repo is static-html-output-plugin, not wp2static. Because, reasons.


Generate static site on server and use Netlify’s CLI tool to deploy

This is a good option for very large sites deploying to Netlify, as only changes will be deployed each time.

  • wp wp2static options set selected_deployment_option folder
  • wp wp2static options set baseUrl https://mystaticsite.netlify.com
  • wp wp2static generate
  • cd "$(cat wp-content/uploads/WP2STATIC-CURRENT-ARCHIVE.txt)"
  • netlify deploy

The Netlify CLI will give you an interactive prompt to follow.


Generate static site on server and deploy via sFTP

Until there is a dedicated Add-on supporting sFTP, the following commands will work.

  • wp wp2static options set selected_deployment_option folder
  • wp wp2static options set baseUrl https://myftpserver.com
  • wp wp2static generate
  • EXPORT_DIR="$(cat wp-content/uploads/WP2STATIC-CURRENT-ARCHIVE.txt)"
  • scp -rp "$EXPORT_DIR" user@server:dest

Generate static site on server and deploy to CloudFlare Workers via Wrangler

Until there is a dedicated Add-on supporting CloudFlare workers, the following commands will work.

  • wp wp2static options set selected_deployment_option folder
  • wp wp2static options set baseUrl https://wp2staticv6test.wp2static.workers.dev/
  • wp wp2static generate
  • EXPORT_DIR="$(cat wp-content/uploads/WP2STATIC-CURRENT-ARCHIVE.txt)"
  • cp -r "$EXPORT_DIR"/* "$MY_WORKER_DIR"/public/
  • cd "$MY_WORKER_DIR"
  • wrangler publish

Above example expects you’ve installed CloudFlare’s Wrangler tool and run wrangler config and wrangler generate --site SITE_NAME. MY_WORKER_DIR above is to be replaced with the actual directory you created with wrangler generate.

Your wrangler.toml will look similar to this:

name = "wp2staticv6test"
type = "webpack"
account_id = "0a5e6f4c0d8a4e4cb4dd08d29e99ddcc"
workers_dev = true

[site]
bucket = "./public"

This example shows how to deploy to your workers.dev domain. Additional configuration is required to deploy to your own domain name. To be updated.