---
title: "How to Update CMS Static Page Programmatically in Magento 2"
url: "https://magecomp.com/blog/update-cms-static-page-programmatically-magento-2/"
date: "2023-03-13T11:52:22+00:00"
modified: "2025-02-14T07:27:10+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 298
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "To Update CMS Static Page Programmatically in Magento 2, create a file in your Magento root directory. Learn more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Add a Custom Button in Page Builder"
    url: "https://magecomp.com/blog/magento-2-add-custom-button-page-builder/"
  - title: "How to Get a value of a Custom attribute of Product in Magento 2 Observer"
    url: "https://magecomp.com/blog/get-value-custom-attribute-product-magento-2-observer/"
  - title: "How to Use Local &#038; Cookie Storage using JavaScript modules in Magento 2"
    url: "https://magecomp.com/blog/use-local-cookie-storage-using-javascript-modules-in-magento-2/"
---

# How to Update CMS Static Page Programmatically in Magento 2

_Published: March 13, 2023_  
_Author: Dhiren Vasoya_  

![How to Update CMS Static Page Programmatically in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/03/How-to-Update-CMS-Static-Page-Programmatically-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In today’s blog, we will learn about How to Update CMS Static Page Programmatically in Magento 2.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

CMS pages help to distribute your content and increase the visibility of products. CMS pages allow promoting your products in various ways to shoppers. You can [**Create CMS Static Page Programmatically in Magento 2**](https://magecomp.com/blog/create-cms-static-page-programmatically-in-magento-2/).
Once you have created the CMS static page, you can update the CMS static page easily. This can be done programmatically in Magento 2. Let’s find out more
## Steps to Update CMS Static Page Programmatically in Magento 2:
**Step 1:** Create a file in your Magento root directory at the below path
**magento_root_directory\update_call.php**

Now add the code as follows
```
<?php
use MagentoFrameworkAppBootstrap;

require './app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

try {
	$pageFactory = $objectManager->create('MagentoCmsModelPageFactory');
	$pageedit = $pageFactory->create()->load(
	    'YOUR_CMS_PAGE_IDENTIFIER',
	    'identifier'
	);

	$content = 'Test Content Set';
	$title = 'Home Page Title';
	$pagelayout = '2columns-left';

	if ($pageedit->getId()) {
            $pageedit->setTitle($title);
            $pageedit->setPageLayout($pagelayout);
            $pageedit->setIsActive(1);
            $pageedit->setContent($content);
            $pageedit->setSortOrder(22);
	    $pageedit->save();
	}
	echo "CMS page updated successfully";

}catch (Exception $e){
    echo "****** Exception Throw ************* n";
    echo $e->getMessage() . " n";
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Output:**

You can see the updated content on the CMS static page
[![](https://magecomp.com/blog/wp-content/uploads/2023/03/update-CMS-static-page-content.png)](https://magecomp.com/blog/wp-content/uploads/2023/03/update-CMS-static-page-content.png)

## Conclusion:
Therefore, you can easily Update CMS Static Page Programmatically in Magento 2. You can also [**Translate CMS Pages in Magento 2**](https://magecomp.com/blog/translate-cms-pages-in-magento-2/). If you face any errors while updating the CMS static page using the above method, share them with me without any hesitation. Stay with us to learn more about Magento 2.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/update-cms-static-page-programmatically-magento-2/](https://magecomp.com/blog/update-cms-static-page-programmatically-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-08 06:57:37 UTC_  
