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>
  • do you want custom breadcrumb for single page? – Manoj Deswal Jul 7 '17 at 6:59
  • Yes, I want every CMS page have separated breadcrumbs. – VijayS91 Jul 7 '17 at 7:03
3

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>
  • Its append exiting breadcrumbs. Like Home >> sample page >> Home >> XXXXXX >> YYYYYY. Kindly hep me to solve. – VijayS91 Oct 30 '17 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 '17 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 '17 at 8:00
2

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

  • Thanks for this one! Worked perfectly in my Magento 2.3 installation. Great Job! – MazeStricks Aug 1 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.

  • 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 '17 at 7:56
  • It's very oddly. What is your Magento version? I tested it on 2.1.4 – Evgeny Levinsky Oct 30 '17 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 '17 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 – Evgeny Levinsky Oct 30 '17 at 12:10

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.