How to delete CMS Static Block programmatically in Magento 2?

You can delete CMS static block programmatically using deleteById() function of Magento\Cms\Api\BlockRepositoryInterface interface.

You just need to inject interface in your constructor and you required only Static Block id to delete specific Block.

You just have to pass Static Block id in deleteCmsBlock() function.

One Reply to “How to delete CMS Static Block programmatically in Magento 2?”

  1. Hi Rakesh,

    This block id is of type integer, so it will be the id which is saved in database table. Can we delete a block using the block identifier which we set from the admin ?

Leave a Reply