3

I have set page title in my custom controller like below

public function execute()
    {
        $resultPage = $this->_resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set(__("My Custom Page");
        return $resultPage;
    }

This displays the title with the title suffix configured in Content->Design->Configuration->Theme edit->HTML Head->Title Suffix

I need to remove title suffix. Can anyone help me?

  • Did you create any layout xml for this page or its a simple cms page? – Sukumar Gorai Sep 19 '18 at 11:38
  • Use this "$resultPage->getConfig()->getTitle()->prepend(__('Brands'));" to set title – Dharmendra Jadav Sep 19 '18 at 11:41
  • @sukumar Gorai. Yes i have created a layout.xml for it. – Pavithra Sep 19 '18 at 11:44
  • @Dharmendra Jadav. using prepend also adds suffix to the title. I am saying about browser tab title... – Pavithra Sep 19 '18 at 11:45
0

You can page title from layout xml like below:

<referenceBlock name="page.main.title">
    <action method="setPageTitle">
        <argument translate="true" name="title" xsi:type="string">My Custom Page</argument>
    </action>
</referenceBlock>

You need to add this blog to your layout xml file.

0

Use Below code for it

<?php

namespace Vendor\Module\Controller\Index;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;


class Index extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;


    public function __construct(
        Context $context, 
        PageFactory $pageFactory,

        )
    {
        $this->_pageFactory = $pageFactory;

        return parent::__construct($context);
    }

    public function execute()
    {        


        $pageFactory = $this->_pageFactory->create();

        // Add title which is got by the configuration via backend
        $pageFactory->getConfig()->getTitle()->set(
           'Custom Page Title'
        );


        return $pageFactory;
    }    
}
0

Try this method prepend(__("My Title")); in your controller.

public function execute()
{
    $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__("Your Title"));
        return $resultPage;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.