As far as I understand, you like to set custom <title>
in the CMS Pages. To do this you have to add new column in the database to store this info. The table is cms_page. Please add column meta_title similar to the title column. Then in app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php
-> protected function _prepareForm()
add this:
$fieldset->addField('meta_title', 'text', array(
'name' => 'meta_title',
'label' => Mage::helper('cms')->__('Title'),
'title' => Mage::helper('cms')->__('Meta Title'),
'disabled' => $isElementDisabled
));
before $fieldset->addField('meta_keywords'
. This way a new field Meta Title will be added in the admin panel -> CMS -> Pages -> tab Meta Data
. To display it in <title>
in app/code/core/Mage/Cms/Block/Page.php
-> protected function _prepareLayout()
replace this:
$head->setTitle($page->getTitle());
with this:
$head->setTitle($page->getMetaTitle() ? $page->getMetaTitle() : $page->getTitle());
So if there is filled Meta Title - it will be displayed otherwise the standard Title will be shown. That's it! Don't forget to flush the cache. And of course it's better to make an extension or at least copy the files in app/code/local
not edit them directly.
For cart page you can use the following piece of code:
<?php $quote = Mage::getSingleton('checkout/cart')->getQuote();
$productIds = "";
foreach($quote->getAllItems() as $item):
if($item->getParentItemId()) continue;
if (strlen($productIds)==0){
$productIds = "'".$item->getSku()."'";
}
else{
$productIds = $productIds.",'".$item->getSku()."'";
}
endforeach;?>
<script>
fbq('track', 'AddToCart', {
content_name: 'Shopping Cart',
content_ids: [<?php echo $productIds?>],
content_type: 'product',
value: <?php echo number_format($quote->getGrandTotal(),2,'.','');?>,
currency: '<?php echo Mage::app()->getStore()->getCurrentCurrencyCode();?>'
});
</script>
For purchase or order confirmation page you can use the following
piece of code -:
<?php $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$productIds = "";
foreach($order->getAllItems() as $item):
if($item->getParentItemId()) continue;
if (strlen($productIds)==0){
$productIds = "'".$item->getSku()."'";
}
else{
$productIds = $productIds.",'".$item->getSku()."'";
}
endforeach;?>
<script>
fbq('track', 'Purchase', {
content_name: 'Order Confirmation',
content_ids: [<?php echo $productIds?>],
content_type: 'product',
value: <?php echo number_format($order->getGrandTotal(),2,'.','');?>,
currency: '<?php echo Mage::app()->getStore()->getCurrentCurrencyCode();?>'
});
</script>
Source:
Untested, but should work. If you are wanting all categories associated you'll need to loop over another collection of the products associated categories to build a list.
<?php $_category = Mage::registry('current_category'); ?>
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '<FB_PIXEL_ID>');
fbq('track', 'PageView');
fbq('track', 'ViewContent', {
content_type: 'product',
content_ids: ['<?php echo $this->getProduct()->getEntityId() ?>'],
content_name: '<?php echo $this->getProduct()->getName() ?>',
content_category: '<?php echo $_category->getName(); ?>',
value: <?php echo $this->getProduct()->getFinalPrice() ?>,
currency: '<?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?>'
});
</script>
Best Answer
Try to use this snippet, that works on sites I´ve worked on and is build up a little different then the one you use right now.
Just give it a try maybe.