How to change a post attribute to homepage using WP CLI?

I want to convert a page to homepage. To add widget to homepage I need to do that. How will I be able to do that using WP CLI?

Topic wp-cli command-line Wordpress

Category Web


To set the site's static home page with WP-CLI, you should be able to do something like this:

wp option update show_on_front "page"
wp option update page_on_front {$page_id}

... where {$page_id} is the ID of the page you want to be the front page.

(Your question was originally tagged multisite—if you're running a Multisite installation, and want to specify a site other than the main site, you'll need to do this:

wp option update show_on_front "page" --url=example.com/site
wp option update page_on_front {$page_id} --url=example.com/site

... where example.com/site is the URL of the site you wish to affect.)

Note: I haven't tested this code. You should try it on a non-production WordPress installation first to be sure it works as intended.

References

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.