brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp widget list shows the widgets in a sidebar

CLI
~/tips/tip-wordpress-wp-widget-list-sidebar

wp widget list <sidebar-id>

Lists the widgets placed in one sidebar, with their ID and position.

Widgets live in a screen I rarely open, so when I want to know what a sidebar holds I’d rather ask WP-CLI.

wp widget list <sidebar-id>

The sidebar ID is required. A theme’s main sidebar is often called sidebar-1, but check what your theme registers. The default table has four columns: name, id, position and options. The options column holds each widget’s settings, so the table gets wide quickly. Trim it with --fields:

wp widget list sidebar-1 --fields=name,id --format=csv

The docs show this output for it:

name,id
meta,meta-5
search,search-3

Those are the docs’ example widgets, yours will differ. --format takes table, csv, ids, json, count and yaml. count is a quick way to see how many widgets a sidebar holds, and json suits scripts.

A caveat: there are no optional fields, so the four above are all you get. If the ID is wrong you won’t get a useful list, which is why the next step is wp sidebar list: it shows the IDs the theme registers.

The sidebar command works the same way. The docs example wp sidebar list --fields=name,id --format=csv prints the name and ID of every registered sidebar. Its default fields are name, id and description, and class, before_widget, after_widget, before_title and after_title are available when you ask for them. The docs also show an --inactive flag, but mark it as not part of a stable WP-CLI release yet.

Once you know the widget ID, other wp widget subcommands act on it: update changes its options, move changes its position, and delete removes it.

Further reading: wp widget list

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link