
Trước đây AZDIGI đã hướng dẫn dùng WP-CLI để quản lý plugin và user trên WordPress. Bài viết này AZDIGI sẽ 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:
- AZDIGI tích hợp WP CLI vào toàn bộ dịch vụ Hosting
- Sử dụng WP CLI quản trị thư viện Plugin
- Hướng dẫn dùng WP CLI để tạo một user mới
Điều đâu tiên thì bạn cần phải truy cập vào Terminal

Tiếp theo bạn cần truy cập đến thư mục chứa website
Ở đây mình muốn quản lý theme website azdigiweb.com . Mình sẽ truy cập vào thư mục chưa mã nguồn azdigiweb.com bằng lệnh cd
AZDIGI Tutorial
[azdigi@azdigi.com ~]$ cd azdigiweb.com/
[azdigi@azdigi.com azdigiweb.com]$
Lưu ý:
- Với domain chính (Primary Domain) thư mục chứa mã nguồn sẽ là public_html
- Với domain addon: thư mục chứa mã nguồn sẽ nằm trong thư mục mang tên domain (nếu ban đầu bạn không thay đổi)
Sử dụng WP-CLI quản lý theme
Xem danh sách theme đang có trên website
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ wp theme list
+-----------------+----------+--------+---------+
| name | status | update | version |
+-----------------+----------+--------+---------+
| oceanwp | inactive | available | 1.7.4 |
| twentynineteen | inactive | none | 1.6 |
| twentyseventeen | inactive | none | 2.3 |
| twentytwenty | active | none | 1.4 |
+-----------------+----------+--------+---------+
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
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ 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 là được.
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ 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.
Kích hoạt theme
Để kích hoạt theme mình sẽ dùng lệnh sau
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ 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
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ 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 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
AZDIGI Tutorial
[azdigi@azdigi.com azdigiweb.com]$ wp theme delete twentynineteen
Deleted 'twentynineteen' theme.
Success: Deleted 1 of 1 themes.
Vậy là AZDIGI đã hướng dẫn bạn cách sử dụng WP-CLI để quản trị theme. Ở bài viết sau AZDIGI sẽ hướng dẫn cài đặt WP-CLI lên VPS chưa hỗ trợ sẵn.

No Comment! Be the first one.