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.


use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;

public function __construct(
    BlockRepositoryInterface $blockRepository
) {
    $this->blockRepository = $blockRepository;

 * @param int $blockId
 * @return bool
public function deleteCmsBlock(int $blockId)
    try {
        $result = $this->blockRepository->deleteById($blockId);
    } catch (LocalizedException $exception) {
        throw $exception->getMessage();
    return $result;

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