2

I have tried the below code for Magento 2 cms page custom breadcrumbs, but I got this error :

Please correct the XML data and try again. Element 'action': This element is not expected. Line: 3

Admin login -> Content-> Pages -> Add New Page -> Design -> Layout Update XML

    <referenceContainer name="breadcrumbs">
        <action method="addCrumb">
            <argument name="crumbName" xsi:type="string">Home</argument>
            <argument name="crumbInfo" xsi:type="array">
                <item name="title" xsi:type="string">Home</item>
                <item name="label" xsi:type="string">Home</item>
                <item name="link" xsi:type="string">/</item>
            </argument>
        </action>
        <action method="addCrumb">
            <argument name="crumbName" xsi:type="string"></argument>
            <argument name="crumbInfo" xsi:type="array">
                <item name="title" xsi:type="string">XXXXXX</item>
                <item name="label" xsi:type="string">XXXXXX</item>
                <item name="link" xsi:type="string">/xxxxxx</item>
            </argument>
        </action>
        <action method="addCrumb">
            <argument name="crumbName" xsi:type="string">YYYYYY</argument>
            <argument name="crumbInfo" xsi:type="array">
                <item name="title" xsi:type="string">YYYYYY</item>
                <item name="label" xsi:type="string">YYYYYY</item>
            </argument>
        </action>
    </referenceContainer>
2
  • do you want custom breadcrumb for single page? Jul 7, 2017 at 6:59
  • Yes, I want every CMS page have separated breadcrumbs.
    – VijayS91
    Jul 7, 2017 at 7:03

4 Answers 4

4

Try below code:

<referenceContainer name="page.wrapper">
<referenceBlock name="breadcrumbs">
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">home</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">Home</item>
            <item name="label" xsi:type="string">Home</item>
            <item name="link" xsi:type="string">/</item>
        </argument>
    </action>
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">cms_page</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">XXXXXX</item>
            <item name="label" xsi:type="string">XXXXXX</item>
            <item name="link" xsi:type="string">/xxxxxx</item>
        </argument>
    </action>
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">yyyyyy</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">YYYYYY</item>
            <item name="label" xsi:type="string">YYYYYY</item>
        </argument>
    </action>
</referenceBlock>
</referenceContainer>
3
  • Its append exiting breadcrumbs. Like Home >> sample page >> Home >> XXXXXX >> YYYYYY. Kindly hep me to solve.
    – VijayS91
    Oct 30, 2017 at 8:05
  • Hi VijayS91. I don't understand what you mean. It is like this? same my image -( prnt.sc/h3shw2 )
    – Linh
    Oct 30, 2017 at 8:53
  • @VijayS91: The above will work. You have to change the crumbName to "home" instead of "Home" and for the second item "cms_page". Then clear your cache and check in the browser.
    – Zammuuz
    Dec 14, 2017 at 8:00
3

You can try this its working for me

Admin login -> Content -> Pages -> Add New Page -> Design -> Layout Update XML

<referenceContainer name="page.wrapper">
    <referenceBlock name="breadcrumbs" remove="true"/>
    <referenceContainer name="page.top">
        <block class="Magento\Theme\Block\Html\Breadcrumbs" name="breadcrumbs.cms">
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string">Home</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string">Home</item>
                    <item name="label" xsi:type="string">Home</item>
                    <item name="link" xsi:type="string">/</item>
                </argument>
            </action> 
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string">CMS Page</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string">CMS Page</item>
                    <item name="label" xsi:type="string">CMS Page</item>
                    <item name="link" xsi:type="string">/cms-page</item>
                </argument>
            </action>
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string">CMS Sub Page</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string">CMS Sub Page</item> 
                    <item name="label" xsi:type="string">CMS Sub Page</item> 
                </argument>
            </action>
        </block>
    </referenceContainer>
</referenceContainer>

Preview

Home >> CMS Page >> CMS Sub Page

1
  • Thanks for this one! Worked perfectly in my Magento 2.3 installation. Great Job! Aug 1, 2019 at 5:49
0

You can to use referenceBlock instead referenceContainer:

<referenceBlock name="breadcrumbs">
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">Home</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">Home</item>
            <item name="label" xsi:type="string">Home</item>
            <item name="link" xsi:type="string">/</item>
        </argument>
    </action>
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string"></argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">XXXXXX</item>
            <item name="label" xsi:type="string">XXXXXX</item>
            <item name="link" xsi:type="string">/xxxxxx</item>
        </argument>
    </action>
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">YYYYYY</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" xsi:type="string">YYYYYY</item>
            <item name="label" xsi:type="string">YYYYYY</item>
        </argument>
    </action>
</referenceBlock>

It's work for me well. I hope it will help.

4
  • Its not working shown this error : Please correct the XML data and try again. Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
    – VijayS91
    Oct 30, 2017 at 7:56
  • It's very oddly. What is your Magento version? I tested it on 2.1.4 Oct 30, 2017 at 8:41
  • Admin login -> Content-> Pages -> Add New Page -> Design -> Layout Update XML Added your code in this text-area and filled necessary fields. Then click the save button shown above comment error. I am work in Magento 2.1.8 version.
    – VijayS91
    Oct 30, 2017 at 10:01
  • In 2.1.4 this code working properly. If you want showing only your items in breadcrumb - you can set option to No in Stores -> Configuration -> tab "General" -> Web -> tab "Default Pages" -> Show Breadcrumbs for CMS Pages Oct 30, 2017 at 12:10
0

I don't understand why above answers fully recreating the breadcrumbs. There's likely nothing wrong with the "Home" breadcrumb and you might get confused as to why the breadcrumbs are positioned differently. Additionally I highly recommend to add translate="true" to the title/label so they are ready for i18n. This would be the minimum needed:

<referenceBlock name="breadcrumbs">
    <action method="addCrumb">
        <argument name="crumbName" xsi:type="string">XXX</argument>
        <argument name="crumbInfo" xsi:type="array">
            <item name="title" translate="true" xsi:type="string">XXX</item>
            <item name="label" translate="true" xsi:type="string">XXX</item>

            <!-- Remove this "link" for the last breadcrumb / to make it non-clickable -->
            <item name="link" xsi:type="string">/xxx</item>
        </argument>
    </action>
</referenceBlock>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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