Skip to content

Adding a custom body class to a page in Magento 2

Today, we will guide you on how to add a custom body class to a specific page (or every page) in Magento 2.

There are two ways to add a body class a page in Magento 2.

  • Add a class via layout XML
  • Programmatically

Add a class via layout XML

Create the file app/code/Dev/Testing/view/frontend/layout/catalog_product_view.xml

Add a class via plugin

Create the file app/code/Dev/Testing/etc/frontend/di.xml

Create the file app/code/Dev/Testing/Plugin/Result/AddClassToBody.php

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap