Magento-2.0 – How to Change Shopping Cart Page Title Programmatically

cartmagento-2.0

I follow this link Change Shopping Cart Title to change Shopping cart to some text via language package.

I need to change Programmaticly Shopping cart Page title to MyCart

I try this

app/design/vendor/theme/Magento_Checkout/layout/checkout_cart_index.xml

    <?xml version="1.0" ?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
       <head><title> My Cart</title></head>

    </page>

Its not Working for me, Suggest me How to Do this…

Best Answer

You need to override here /app/code/Magento/Checkout/Controller/Cart/Index.php

find the below line

$resultPage->getConfig()->getTitle()->set(__('Shopping Cart'));

and change to

$resultPage->getConfig()->getTitle()->set(__('Whatever Title You Need'));

for alternate solution you can create own module that contains a translation file i18n/en_US.csv. here you can translate your phrase

'Shopping Cart','Whatever Title You Need'

for one more alternate solution you can try with in your theme too

magento2/app/design/frontend/Vendor/Theme/i18n/en_US.csv

'Shopping Cart','Whatever Title You Need'