-
Notifications
You must be signed in to change notification settings - Fork 357
Docs: Updated documentation for wp sidebar command
#620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
iamsohilvahora
wants to merge
1
commit into
wp-cli:main
from
iamsohilvahora:update/update_wp_sidebar_doc
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,190 @@ | ||
| # wp sidebar | ||
|
|
||
| Lists registered sidebars. | ||
| Lists registered sidebars in WordPress. | ||
|
|
||
| A [sidebar](https://developer.wordpress.org/themes/functionality/sidebars/) is any widgetized area of your theme. | ||
| ## Description | ||
|
|
||
| ### EXAMPLES | ||
| A [sidebar](https://developer.wordpress.org/themes/functionality/sidebars/) is any widgetized area of your theme where widgets can be placed and displayed. Sidebars are typically used for features like: | ||
|
|
||
| # List sidebars | ||
| $ wp sidebar list --fields=name,id --format=csv | ||
| name,id | ||
| "Widget Area",sidebar-1 | ||
| "Inactive Widgets",wp_inactive_widgets | ||
| - Navigation menus | ||
| - Recent posts widgets | ||
| - Category listings | ||
| - Search boxes | ||
| - Custom content areas | ||
| - Footer content regions | ||
|
|
||
| The `wp sidebar` command provides tools to inspect, manage, and query the sidebars registered in your WordPress installation, whether they are active or inactive. | ||
|
|
||
| ## Subcommands | ||
|
|
||
| ### wp sidebar list | ||
|
|
||
| Lists all registered sidebars on your site. | ||
|
|
||
| #### Options | ||
|
|
||
| | Option | Description | Type | Default | | ||
| |--------|-------------|------|---------| | ||
| | `--fields` | Limit the output to specific fields (e.g., `name,id,description`) | string | all | | ||
| | `--format` | Render output in a specific format (`table`, `csv`, `json`, `count`) | string | table | | ||
| | `--exclude-inactive` | Exclude inactive sidebar areas | boolean | false | | ||
| | `--search` | Search sidebars by name | string | none | | ||
|
|
||
| #### Common Fields | ||
|
|
||
| - **name**: The human-readable name of the sidebar | ||
| - **id**: The unique identifier for the sidebar | ||
| - **description**: A brief description of the sidebar | ||
| - **class**: CSS class assigned to the sidebar | ||
| - **before_widget**: HTML markup before each widget in the sidebar | ||
| - **after_widget**: HTML markup after each widget in the sidebar | ||
| - **before_title**: HTML markup before widget titles | ||
| - **after_title**: HTML markup after widget titles | ||
|
|
||
| ## Examples | ||
|
|
||
| ### List all sidebars with name and ID | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --fields=name,id | ||
| +-----------------+-----------------+ | ||
| | name | id | | ||
| +-----------------+-----------------+ | ||
| | Widget Area | sidebar-1 | | ||
| | Inactive Widgets| wp_inactive_widgets | | ||
| +-----------------+-----------------+ | ||
| ``` | ||
|
|
||
| ### Export sidebars as CSV | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --fields=name,id --format=csv | ||
| name,id | ||
| "Widget Area",sidebar-1 | ||
| "Inactive Widgets",wp_inactive_widgets | ||
| ``` | ||
|
|
||
| ### Export sidebars as JSON | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --format=json | ||
| [ | ||
| { | ||
| "name": "Widget Area", | ||
| "id": "sidebar-1", | ||
| "description": "Main sidebar area", | ||
| "class": "widget-area" | ||
| }, | ||
| { | ||
| "name": "Inactive Widgets", | ||
| "id": "wp_inactive_widgets", | ||
| "description": "", | ||
| "class": "" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| ### Count total sidebars | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --format=count | ||
| 2 | ||
| ``` | ||
|
|
||
| ### Display sidebars with descriptions | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --fields=name,description | ||
| +--------------------+--------------------------------------+ | ||
| | name | description | | ||
| +--------------------+--------------------------------------+ | ||
| | Primary Sidebar | Main sidebar in the page layout | | ||
| | Footer Widgets | Footer widget area (4 columns) | | ||
| | Inactive Widgets | Area for unused widgets | | ||
| +--------------------+--------------------------------------+ | ||
| ``` | ||
|
|
||
| ### List sidebars excluding inactive ones | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --fields=name,id --exclude-inactive | ||
| +------------------+----------+ | ||
| | name | id | | ||
| +------------------+----------+ | ||
| | Primary Sidebar | sidebar-1| | ||
| | Footer Widgets | footer-1 | | ||
| +------------------+----------+ | ||
| ``` | ||
|
|
||
| ### Search for a specific sidebar | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --search=Footer --fields=name,id | ||
| +-----------------+---------+ | ||
| | name | id | | ||
| +-----------------+---------+ | ||
| | Footer Widgets | footer-1| | ||
| +-----------------+---------+ | ||
| ``` | ||
|
|
||
| ### Get sidebar information with HTML markup | ||
|
|
||
| ```bash | ||
| $ wp sidebar list --fields=name,id,before_widget,after_widget --format=json | ||
| [ | ||
| { | ||
| "name": "Widget Area", | ||
| "id": "sidebar-1", | ||
| "before_widget": "<div id=\"%1$s\" class=\"widget %2$s\">", | ||
| "after_widget": "</div>" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| ## Common Use Cases | ||
|
|
||
| ### Export sidebar structure for backup or documentation | ||
|
|
||
| ```bash | ||
| wp sidebar list --format=json > sidebars_backup.json | ||
| ``` | ||
|
|
||
| ### Verify sidebar registration in a theme | ||
|
|
||
| ```bash | ||
| wp sidebar list --fields=name,id | ||
| ``` | ||
|
|
||
| ### Automate widget area setup scripts | ||
|
|
||
| ```bash | ||
| wp sidebar list --format=csv | tail -n +2 | while IFS=',' read -r name id; do | ||
| echo "Processing sidebar: $name ($id)" | ||
| done | ||
| ``` | ||
|
|
||
| ### Integration with other commands | ||
|
|
||
| ```bash | ||
| # List only active sidebars and count them | ||
| wp sidebar list --exclude-inactive --format=count | ||
| ``` | ||
|
|
||
| ## Tips & Best Practices | ||
|
|
||
| 1. **Use `--format=json`** for programmatic access and scripting | ||
| 2. **Combine with `--fields`** to reduce output noise and focus on needed information | ||
| 3. **Verify sidebars exist** before registering widgets with them in custom scripts | ||
| 4. **Use `--search`** to quickly locate specific sidebars in theme with many registered areas | ||
| 5. **Export as CSV** for spreadsheet analysis or documentation purposes | ||
|
|
||
| ## Resources | ||
|
|
||
| - [WordPress Sidebars Documentation](https://developer.wordpress.org/themes/functionality/sidebars/) | ||
|
|
||
| ## Notes | ||
|
|
||
| - The `wp_inactive_widgets` sidebar is a special WordPress sidebar where widgets can be placed but won't be displayed on the site | ||
| - Sidebar IDs must be unique within a WordPress installation | ||
| - Sidebars are typically registered in theme `functions.php` files using `register_sidebar()` | ||
| - Different themes may have different sidebar configurations | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to end all text files with a newline character. This helps with consistency and avoids potential issues with some tools or version control systems.