how to create a right sidebar in magento which will be visible only on product view page

how to create a right sidebar in magento which will be visible only on product view page

October 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
how to create a right sidebar in magento which will be visible only on product view page

Creating a Right Sidebar Visible Only on Magento Product View Page

Hello, developers! In this post, I’ll guide you through creating a right sidebar that displays only on the Magento product view page. This is a common requirement for many e-commerce stores.

Understanding the Magento Layout System

Before we dive into the code, let’s quickly review how Magento manages its layout system. Magento uses XML files to define the layout of your storefront pages. The catalog_product_view.xml file controls the layout of the product view page.

You can find this file in:

app/design/frontend/<Your_Theme>/<Your_Version>/layout/catalog.xml

Creating Your Right Sidebar

To create a new sidebar, follow these steps:

Step 1: Create a New XML File for Your Sidebar

Navigate to your theme directory (replace <Your_Theme> and <Your_Version> with your actual theme name and version):

app/design/frontend/<Your_Theme>/<Your_Version>/layout

Create a new file called catalog_product_view_sidebar.xml. This file will define the layout for our sidebar.

Step 2: Define Your Sidebar in the XML File

Open your newly created catalog_product_view_sidebar.xml file and add the following content:

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generated_xsd">
    <update handle="catalog_product_view"/>
    <referenceBlock name="page.main.content">
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/pager.phtml" after="-" name="custom.sidebar" />
    </referenceBlock>
</layout>

This code tells Magento to load the default product view layout and then add a new block called custom.sidebar after the main content area.

Step 3: Create Your Sidebar Template

Now, let’s create the actual HTML for our sidebar. In your theme directory:

app/design/frontend/<Your_Theme>/<Your_Version>/template

Create a folder called Magento_Theme if it doesn’t exist. Inside this folder, create another folder called html, and finally create a file named custom_sidebar.phtml.

Open the custom_sidebar.phtml file and add your sidebar HTML content. For example:

<div class="sidebar-wrapper">
    <h2>Our Special Products</h2>
    <ul>
        <li><a href="#">Product 1</a></li>
        <li><a href="#">Product 2</a></li>
        <!-- Add more product links as needed -->
    </ul>
</div>

Step 4: Include Your Sidebar in the Product View Page

To make sure your sidebar appears on the product view page, you need to include it in the catalog_product_view.xml file.

Open this file (the path is mentioned at the beginning of this post) and add the following line inside the <layout> tag:

<referenceBlock name="custom.sidebar" template="Magento_Theme::html/custom_sidebar.phtml"/>

Save all your changes.

Checking Your Work

Now, when you navigate to a product page on the frontend, you should see your custom right sidebar appear. The sidebar will be visible only on this page and not on any other pages in your storefront.

Please note that if you haven’t enabled the template path hints feature, you might need to enable it in the backend (Stores > Configuration > Advanced > Developer) to see the layout XML file names directly on the frontend.

Conclusion

Creating a right sidebar visible only on the product view page is quite straightforward once you understand Magento’s layout system. By following the steps outlined above and applying them to your own theme, you should be able to achieve this functionality with ease.

Remember, it’s always a good practice to start by creating child themes when making customizations like these. This helps keep your changes separate from the core theme files and makes updates easier to manage.

For more advanced Magento development topics, I recommend checking out LaravelCompany’s Magento Development Services. Their team of experienced developers can provide you with expert guidance on a wide range of e-commerce projects.

Catalog Themes

Our network