[WP-CLI] – Quản lý theme
Trước đây mình đã hướng dẫn dùng WP-CLI để quản lý user trên WordPress. Bài viết này mình sẽ tiếp tục hướng dẫn các bạn sử dụng WP-CLI để quản lý theme.
Bài viết về WP-CLI bạn có thể xem lại:
Điều đâu tiên thì bạn cần phải truy cập vào thư mục chứa mã nguồn website thông qua công cụ SSH.
Ví dụ mã nguồn trên Cpanel sẽ nằm trong thư mục cùng tên miền, còn trên EasyEngine và WordOps bạn chỉ cần nhập lệnh shell tương ứng để truy cập WP-CLI.
Sử dụng WP-CLI quản lý theme
Xem danh sách theme đang có trên website
^_^[[email protected]:~/htdocs]$ wp theme list +-----------------+----------+--------+---------+ | name | status | update | version | +-----------------+----------+--------+---------+ | oceanwp | inactive | none | 1.8.3 | | the-newsmag | active | none | 1.0.5 | | twentyseventeen | inactive | none | 2.3 | +-----------------+----------+--------+---------+
Cài theme mới
Tìm một theme
Mình sẽ tìm theme có tên là Newsmag, mình nhập newsmag để tìm theme nào có tên này.
^_^[[email protected]:~/htdocs]$ wp theme search newsmag Success: Showing 3 of 3 themes. +-----------------+-----------------+--------+ | name | slug | rating | +-----------------+-----------------+--------+ | NewsMag | newsmag | 92 | | The NewsMag | the-newsmag | 100 | | MH NewsMagazine | mh-newsmagazine | 0 | +-----------------+-----------------+--------+
Cài theme
Mình sẽ cài theme The NewsMag, bạn chỉ cần nhập lệnh install với tên slug tương ứng là được.
^_^[[email protected]:~/htdocs]$ wp theme install the-newsmag Installing The NewsMag (1.0.5) Downloading installation package from https://downloads.wordpress.org/theme/the-newsmag.1.0.5.zip… Unpacking the package… Installing the theme… Theme installed successfully. Success: Installed 1 of 1 themes.
Bạn có thể thêm option --activate
để sau khi cài đặt xong theme sẽ tự kích hoạt luôn.
Kích hoạt theme
Để kích hoạt theme đang có sẵn trên website thì mình sẽ dùng lệnh sau
^_^[[email protected]:~/htdocs]$ wp theme activate the-newsmag Success: Switched to 'The NewsMag' theme.
Update theme
Bạn có theme cần update, hãy nhập lệnh sau
^_^[[email protected]:~/htdocs]$ wp theme update oceanwp Downloading update from https://downloads.wordpress.org/theme/oceanwp.1.8.3.zip… Unpacking the update… Installing the latest version… Removing the old version of the theme… Theme updated successfully. +---------+-------------+-------------+---------+ | name | old_version | new_version | status | +---------+-------------+-------------+---------+ | oceanwp | 1.7.4 | 1.8.3 | Updated | +---------+-------------+-------------+---------+ Success: Updated 1 of 1 themes.
Để update toàn bộ theme có trên website thì bạn thêm option -all
vào phía sau câu lệnh là được.
Delete theme
Ví dụ mình cần delete theme twentynineteen thì nhập lệnh như sau
^_^[[email protected]:~/htdocs]$ wp theme delete twentyseventeen Deleted 'twentyseventeen' theme. Success: Deleted 1 of 1 themes.
Chúc các bạn thành công. Nếu không thao tác được có thể bình luận hoặc gửi hỗ trợ cho mình nhé.