1

How to change the homepage in WordPress via CLI.

e.g I have one page called "Home1" and I want to make that page the homepage. In other words, I want to change the "Static Page" via CLI.

3UMF
  • 5,162
  • 2
  • 15
  • 26
  • You can find the solution here: https://wordpress.stackexchange.com/questions/344242/how-to-change-a-post-attribute-to-homepage-using-wp-cli – Akash Agrawal Dec 03 '19 at 11:19
  • This one is not working. Option "A static page " should be checked also at "Homepage Settings". To complete this task it should check option(A static page) via CLI and use those lines of code from the linke you recommend. – 3UMF Dec 03 '19 at 13:30

3 Answers3

4
#Listing all pages
wp post list

#Listing all pages with type page
wp post list --post_type='page'

#Updates an option value for example the value of Simple page is id = 2
wp option update page_on_front 2

#Update the page as front page by default.
wp option update show_on_front page 
3UMF
  • 5,162
  • 2
  • 15
  • 26
  • 1
    Once I faced an issue regarding a WP site where the home page was showing a 404. I used the command wp option update page_on_front 2 and replaced 2 with my page ID. It worked! – Mushrit Shabnam Jan 21 '21 at 05:45
3

You can use the wp options update command, see the documentation

wp option update show_on_front 'page' --path="WORDPRESS_PATH"
wp option update page_on_front pageId --path="WORDPRESS_PATH"
3UMF
  • 5,162
  • 2
  • 15
  • 26
zarex360
  • 312
  • 4
  • 16
  • It is not working. When I go at Customize mode, at the "Homepage Settings" menu option both options(1. Your latest posts and 2. A static page) are unchecked. To complete this task it should check the second option(A static page) via CLI. – 3UMF Dec 03 '19 at 13:09
0

first of install the WP-CLI in your system. here,is the reference for how to install the wp-cli

https://wp-cli.org/

https://www.sitepoint.com/wp-cli/

https://make.wordpress.org/cli/handbook/installing/

after succesfully install wpcli use wp option command

syntax :- wp option update page_on_front {$page_id} --allow-root
example :- wp option update page_on_front "14" --allow-root
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57