hi guys,
how can i edit magento 2 home page title (head title) programmatically .
guide me ?
Hi @bharath553
Please try the below code to change the cms page title
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cmsPageFactory = $objectManager->create('Magento\Cms\Model\PageFactory');
$homePage = $cmsPageFactory->create()->load('Page Id or Url ');
$homePage->setTitle("Changes Title")->save();
Problem solved? Click Kudos & Accept as Solution!
Thanks
Please try this,
1. From controller
/** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->getConfig()->getTitle()->set('Something');
2. From layout module_controller_action.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> <title>Something..</title> </head> </page>
You need to do below in your controller file,
public function execute() { $resultPage = $this->resultPageFactory->create(); $pageMainTitle = $resultPage->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle(__('My Homepage')); } return $resultPage; }
NO , i just want to edit the title in code. where can i find that code ?
Hi,
Please check the below configuration changes.
Go to the Admin panel > Content > Pages > Choose the Homepage > In the field "Page Title" add a new title you want to show > click on Save button.
or
Go to Admin Panel > Go to System > Configuration > Choose Design, open HTML Head tab > Enter your title in "Default title" field > Save Config
Hope it helps!