Rendering HTML Output with WP-CLI

Have you ever had an issue with an individual WordPress page or post that required the use of a staging site? I’ve previously explored troubleshooting directly on the production site with WP Freighter and WP Shipyard. Today, we’ll look at a new way of troubleshooting plugin issues using WP-CLI.

Render Command is a WordPress plugin that provides a WP-CLI command wp render to output raw HTML for a requested URL.

You can install the Render Command plugin using WP-CLI like this.

wp plugin install https://github.com/austinginder/render-command/releases/latest/download/render-command.zip --activate

This allows you to render any URL on your websites. Rendering the homepage is as simple as:

wp render "/"

I created Render Command primarily to see what a URL looks like without a certain plugin active. This would render the about page while excluding Jetpack and Yoast SEO:

wp render "/about-us/" --without-plugins="jetpack,wordpress-seo"

Under the hood, this works by leveraging a must-use plugin to conditionally remove certain plugins from the request via query strings with wp_remote_get. Modifying the active plugins seems to only work by using a must-use plugin due to the way WordPress boots up. While I would recommend deactivating the Render Command plugin after you’re done using it, it does communicate using a unique token, so it shouldn’t be a security risk if left installed.

Another fun thing you can do with wp render is output the HTTP code. This is helpful as you can loop through all active plugins on a particular URL to check for HTTP code changes like this:

for plugin in $( wp plugin list --status=active --field=name --skip-plugins ); do
   echo "Without $plugin $(wp render "/" --without-plugins="$plugin" --format=http_code --quiet 2>/dev/null )"
done
Without blocksy-companion-pro 200
Without disembark-connector 200
Without disembark-interface 200
Without render-command 200
Without sqlite-database-integration 200

Requesting a URL without a plugin will also output the customized link used. This is helpful if you’d like to preview that URL in the browser. You can hide these notices with --quiet.

That’s pretty much it. Check out the GitHub readme if you have ideas for additional features or want to try it out for yourself: https://github.com/austinginder/render-command.