1

I have a custom CMS page with the url of /test

I tried pasting this in the Layout Update XML under Page Layout AND also tried under the Custom Theme Layout Update XML.. both options do not work

<referenceContainer name="before.body.end">
    <block class="Magento\Cms\Block\Block">
        <arguments>
            <argument name="block_id" xsi:type="string">sale_campaign_canonical</argument>
        </arguments>
    </block>
</referenceContainer>

This sale_campaign_canonical is a static block available on all storefronts and has

<link rel="canonical" href="/test" />

Inside of it

Thanks

1 Answer 1

-4

Use "widgets"

enter image description here

content > widgets > Add Widget | Type: CMS Block / Design Theme (Your Design)

enter image description here

Then, in storefront properties, you can choose where you want it to be/load "all Pages" or "All Product Pages" and then select "Page Header".

enter image description here

Then select your CMS Block

enter image description here

The new widget functions in Magento 2 are really helpful for putting CMS Blocks where you need. Meta tags, scripts, static information or just about anything. It's really simple, easy to use and you can turn it on or off at will. I used it to add microdata meta tags for condition as well as adding product tabs to certain products/categories. It's very versatile.

4
  • Where is a good reference to see how and where we can add blocks? Like adding things after footers, in head, in DOCTYPE and in body etc.. this is really interesting I will try this now.. the documentation I think is not as friendly... Commented Apr 20, 2017 at 10:15
  • I really haven't seen anything that's not so ridiculously complicated or changing files, while almost all of the really good stuff can be done 100% in the backend. I was just playing around and found it and holy cow! devdocs.magento.com/guides/v2.1/javascript-dev-guide/widgets/… That has some interesting information. But without adding any code, you can put in pop-up DIVs for login, or whatever you want really. The one for tabs is complicated, but really amazing and you can add a text attribute when adding products to include only specific tabs per product
    – dawhoo
    Commented Apr 20, 2017 at 16:47
  • This doesn't work as it adds the canonical tag in the header of the body of the page and will therefore be ignored Commented Mar 13, 2018 at 1:43
  • @ChrisRogers You're doing something wrong then if it's adding your CMS to the header and the body.
    – dawhoo
    Commented Mar 13, 2018 at 2:06

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.