How to Add Magento Product Video Programmatically

How to Add Video to Product page in Magento

Attach video to your product page in Magento store to provide detailed information to your customers about the product. A video is better than a thousand words and can cover more information in less time. Customers can find videos especially useful if they want to know how the product works or what features and benefits it offers.

Adding video to product page is easy. Although there are extensions available which you can buy to get the task done, most of the times the extensions don’t meet the customer’s requirements. Moreover, if you want to add the video to a particular place such as top or sidebar, the extensions possibly won’t help you.

In order to add video to your product page in Magento through custom coding, you can do the following:

1.       Create “video” text input attribute. Add it to appropriate attribute set and reindex your data.

2.       The following file will help you to find the place where you want to place the video.

app/design/frontend/yourpackage/yourtheme/template/catalog/product/view.phtml

3.       Find the following code if you want to add the video under the product name.

<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>

4.       Insert the following code. It will add the video under the product name.

<?php if($_product->getVideo()): ?>

<iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo $_product->getVideo() ?>" frameborder="0" allowfullscreen></iframe>

<?php endif; ?>

Now you just have to paste the video UID (Unique Identifier) into the video attribute field to display the video.  For example, xbL0ab22WEc is the UID in https://www.youtube.com/watch?v=xbL0ab22WEc.

One thought on “How to Add Magento Product Video Programmatically

Leave a Reply

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