This WordPress plugin provides useful WP-CLI commands for managing Gutenberg blocks.
Searches for every instance of a specific Gutenberg block in your WordPress database.
--block-slug=<slug>
: (required) The slug of the Gutenberg block to search for.--site-id=<id>
: (optional) The ID of the site to search in. If not provided, the command will search in all sites.--post-type=<type>
: (optional) The type of the posts to search in. Defaults to 'post'.--file=<filename>
: (optional) The name of the file to write the search results to. Defaults to 'block-search.csv'.
wp block-tools search --block-slug=paragraph
Removes a specific Gutenberg block from your WordPress posts.
--block-slug=<slug>
: (required) The slug of the Gutenberg block to remove.--site-id=<id>
: (required in multisite installations) The ID of the site to remove the block from. If not provided, the command will remove the block from all sites.--post-type=<type>
: (required) The type of the posts to remove the block from. Multiple post types can be provided as a comma-separated list.
wp block-tools remove --block-slug=paragraph --site-id=1 --post-type=post,page
Scans posts of a specified post type or all post types and lists every unique block that has been used.
--post-type=<slug>
: (optional) The slug of the post type you want to audit orall
which will scan all post types as well as 'wp_block', 'wp_template' and 'wp_template_part'. Defaults topost
.
wp block-tools audit --post-type=all
- Download the plugin and extract it to your
wp-content/plugins
directory. - Activate the plugin in your WordPress admin dashboard.
- The WP-CLI commands will be available in your command line.
- The
block-tools search
command writes the search results to a CSV file in the WordPress uploads directory. The CSV file includes the post ID, post URL, post title, block type, content excerpt, and block attributes. - The
block-tools search
command can only be run on a WordPress Multisite installation if theswitch_to_blog
function is available. - The
block-tools search
command uses theLIKE
SQL operator to search for the block slug in the post content, so it may return false positives if the block slug is found in the content of other blocks or in the text content. - The
block-tools remove
command uses a regular expression to remove the block from the post content. It removes the entire block, including the block attributes and inner content. - The
block-tools remove
command only removes the block from published posts. Drafts, scheduled posts, and other post statuses are not affected. - The
block-tools remove
command outputs a success message indicating that the block has been removed from all specified post types in the given site. If a post type does not exist, it skips that post type and outputs a warning message. - The
block-tools remove
command can only be run on a WordPress Multisite installation if theswitch_to_blog
function is available. - The
block-tools remove
command requires a valid site ID in multisite installations. If a site ID is not provided or is not valid, it outputs an error message and does not run the command.