Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:36:07+00:00 2026-05-30T05:36:07+00:00

I’m looking for a solution in PHP to programmatically set the CMS home page

  • 0

I’m looking for a solution in PHP to programmatically set the CMS home page in Magento. What I’m looking for is what you get when you use the manual method of selecting a page title from the dropdown in the System->Configuration->Web->CMS Home Page.

I already have the methods to determine pick any one of the set of Page Titles or I can pick from the Set of URL keys for all the CMS pages in the store. If I know either the Page Title or the URL Key, what is the PHP Mage methods to needed to change the current CMS home page.

I have already figured the code to create a new CMS Page as well. I’d just like to be able to select it and make it actively the home page when I’m done.

Edit: 02/18/2012

tried the following without success:

    $groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';

    Mage::getModel('adminhtml/config_data')
        ->setSection('web')
        ->setWebsite('Main Website') 
        ->setStore('My Store Name') // Hid Actual Store name here
        ->setGroups($groups)
        ->save();

EDIT: Thanks for the screenshot. I didn’t have those right. My url when selecting the store is …/index.php/admin/system_config/edit/section/general/website/base/store/default/

Which I assume means website=base, store=default

website store
(source: reefworkshop.com)

I changed the code to:

    $groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';

    Mage::getModel('adminhtml/config_data')
        ->setSection('web')
        ->setWebsite('base') 
        ->setStore('default')
        ->setGroups($groups)
        ->save();

But I’m still not showing the CMS Home page selected change. I refresh the front end and it doesn’t switch. I’ve also tried clearing cache with no luck. Any ideas? just FYI I’m running Magento CE 1.5.1.0

EDIT:

Here’s the file contents that I run. I put the file at the root of my Magento Install.:

<html>
    <head>
    </head>
    <body>
       <?php      
        require_once('app/Mage.php'); //Path to Magento
        umask(0);
        Mage::app(); // Change default to whatever store you want to run

        print('CMS 1<br>'); 
        $groups['default']['fields']['cms_home_page']['value'] = 'city-grips-handle-bar-covers';

        print('CMS 2<br>'); 
        Mage::getModel('adminhtml/config_data')
            ->setSection('web')
            ->setWebsite('base') // Code is the field name
            ->setStore('default')
            ->setGroups($groups)
            ->save();

        print('CMS 3<br>'); 
        ?>          
     </body>
 </html>

When I run it is see in the browser window:

CMS 1
CMS 2
CMS 3

EDIT:
OK So I found a solution (that works) that was inspired by the last proposed solution:

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run

$Config = new Mage_Core_Model_Config();
$Config ->saveConfig('web/default/cms_home_page', "city-grips-handle-bar-covers");
Mage::app()->cleanCache();

Voila it works. The configuration cache is really all that it needed to be cleaned (I confirmed this manually). So cleaning all the cache is a little overkill but oh well it works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:36:08+00:00Added an answer on May 30, 2026 at 5:36 am

    Here it is. This works on the default store and will change the CMS Home Page to whatever you put in . Obviously a CMS page with this URL must exist. You’ll get an error on the front end if you specify one that does not exist.

    require_once('app/Mage.php'); //Path to Magento
    umask(0);
    Mage::app(); // Change default to whatever store you want to run
    
    $Config = new Mage_Core_Model_Config();
    $Config ->saveConfig('web/default/cms_home_page', "<URL-Key-goes-here>");
    Mage::app()->cleanCache();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.