How to Create and Delete a WordPress Page Using WP-CLI

In This Tutorial:

Create a Page Delete a Page

WP-CLI is a tool available with any of InMotion Hosting’s WordPress Hosting plans. This ingenious suite of tools allows you to work on your WordPress websites from the command line. In this guide, you will learn how to create and delete a WordPress Page from the command line using the WP-CLI command, wp post.

Add a Page

  1. SSH into your server as the cPanel user that owns the website you would like to work with.

  2. Use the cd command to switch to the document root directory of your website.

    Example: cd public_html/wp

  3. Run the following command:

    wp post create –post_type=page

  4. The output will be similar to the example below:

    [email protected] [~/public_html/wp]# wp post create --post_type=page Success: Created post 157.

Delete a Page

  1. SSH into your server as the cPanel user that owns the website you would like to work with.

  2. Use the cd command to switch to the document root directory of your website.

    Example: cd public_html/wp

  3. Run the following command:

    wp post delete 156

  4. The output will be similar to the example below:

    [email protected] [~/public_html/wp]# wp post delete 156 Success: Trashed post 156.

Congratulations! Now, you know how to create and delete WordPress Pages, using WP-CLI.

Learn more about WP-CLI, the command-line interface for WordPress, and streamline your WordPress maintenance workflow!

JB
John-Paul Briones

John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

More Articles by John-Paul

Was this article helpful? Let us know!