How to create a CMS page programmatically in Magento 2?

For creating a CMS page programmatically, please use the below instructions:How to create a CMS page programmatically in Magento 2?How to create a CMS page programmatically in Magento 2?

How to create a CMS page programmatically in Magento 2?expoundsofttechsolution What is GMT?

  1. You need to create the UpgradeData.php in Setup folder in your module.
  2. After that add this code in your file.
<?php
 
namespace Vendor\Module\Setup;
 
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
 
/**
 * @codeCoverageIgnore
 */
class UpgradeData implements UpgradeDataInterface
{
    /**
     * @var \Magento\Cms\Model\PageFactory
     */
    protected $_pageFactory;
 
    /**
     * Construct
     *
     * @param \Magento\Cms\Model\PageFactory $pageFactory
     */
    public function __construct(
        \Magento\Cms\Model\PageFactory $pageFactory
    ) {
        $this->_pageFactory = $pageFactory;
    }
 
    /**
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     */
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
 
        if (version_compare($context->getVersion(), '1.1') < 0) {
            $page = $this->_pageFactory->create();
            $page->setTitle('Ests page')
                ->setIdentifier('ests-page')
                ->setIsActive(true)
                ->setPageLayout('1column')
                ->setStores(array(0))
                ->setContent('Ests')
                ->save();
        }
 
        $setup->endSetup();
    }
}

3. Run the setup upgrade command
bin/magento setup:upgrade