I am trying to change "Shopping Cart" to "Basket" on both the h1.page-title
and in the <title>
tag itself.
Where can I change this?
You can change this directly in the checkout i18l file:
app/code/Magento/Checkout/i18n/en_US.csv
in your theme, like:
app/design/frontend/Vendor/theme/i18n/en_US.csv
Just change string translation like this:
"Shopping Cart","Basket"
Result:
Or you can create a language pack https://devdocs.magento.com/guides/v2.3/config-guide/cli/config-cli-subcommands-i18n.html
To translate a minicart title you must run setup:static-content:deploy
with required parameters (More Info in DevDocs). After that translations must present in the js-translation.json
file (pub/static/frontend/Vendor/theme/en_US/js-translation.json
):
and result will be visible on the frontend:
The best and easiest solution that I found and that will not affect the default MAGENTO 2 structure (just changed under my theme) is by Prashant Valanda on "How to modify page title?" article.
Basically you just need to add this code in your XML
file. In this case checkout_cart_index.xml
:
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument translate="true" name="title" xsi:type="string">Basket</argument>
</action>
</referenceBlock>
After change doesn't forget to flush the cache.
php bin/magento cache:flush
I found in my case where I needed to change the <title/>
tag, an "after" plugin can be used on the cart Index->execute();
controller method.
The page title is set in
\** \Magento\Checkout\Controller\Cart\Index **\
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('Shopping Cart'));
return $resultPage;
}
Here is my plugin afterExecute()
/**
* Custom cart index page
*
* @return \Magento\Framework\View\Result\Page
*/
public function afterExecute(
\Magento\Checkout\Controller\Cart\Index $cartIndex,
$resultPage
)
{
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('TITLE TAG CONTENT HERE'));
$titleBlock = $resultPage->getLayout()->getBlock('page.main.title');
if ($titleBlock) {
$titleBlock->setPageTitle(
__('PAGE CONTENT TITLE HERE')
);
}
return $resultPage;
}