Magento v1.9.x如何仅自定义产品详细信息页面的头部代码?

I want to add OG tags to the product detail page in Magento for the PDP (product detail page) only.

Is there a way to add code in between the head tags for the PDP only?

The two approaches I'm thinking of: 1) is there a head.phtml for the PDP only that I can edit (that I just don't know about)? =-OR-= 2) adjust the regular head include and somehow look at the page and dump out the data that way.

NOTES(this is for): Magento v1.x (my store is updated to 1.9.2). The code is product data only meant for the PDP.

thank you in advance.

First, you'll need to check current page is product detail page then you have to check by either by controller or router . Here we have checked using the controller . Go to to head.phtml file write following code .

<?php
 $this->getRequest()->getControllerName();
if($this->getRequest()->getControllerName()=='product') {?>
    <?php // write your og tag here for eg. ?>
    <meta property="og:type" content="website" />


<?php }

?>

You can target product detail page using handler catalog-product-view. Make local.xml in your theme and add

    <catalog_product_view>
      <reference name="head">
        // your action
       </reference>
    </catalog_product_view>

in your action you can try <action method="addCss”> or <action method="addJs"> or <![CDATA[ / ]]> to set anything in header.

<? if(Mage::registry('current_product')){ //your product page only code } ?>

The above if statement should return true only if you're on a product page. You should be able to use this to add product page exclusive code to your head.phtml