質問

I am trying to set my own custom canonical links in Magento for products through the use of a custom attribute but I cannot get the attribute to echo in the head.phtml file. This is what I have so far. Please can anybody help?

<?php if (Mage::registry('current_product')) : ?>
<?php $customcanonical = Mage::registry(‘current_product’)->getData(‘canonical_link’); ?>
<link rel="canonical" content="<?php echo $customcanonical ?>" />
<?php endif; ?>

where canonical_link is my custom attribute

役に立ちましたか?

解決

Try something like this:

<?php if ($_product = Mage::registry('current_product')) : ?>
<?php $customcanonical = $_product->getData('canonical_link'); ?>
<?php if ($customcanonical): ?>
<link rel="canonical" content="<?php echo $customcanonical ?>" />
<?php endif; ?>
<?php endif; ?>

Also make sure your 'canonical_link' attribute is in the currently used attribute set and has an assigned value for the current product you're viewing. Make sure you reindex too if this attribute or product is new (or if using a flat catalog!) And finally, if you have caching on, make sure you flush it in order for new changes to appear (or disable it while you develop new features for your site in a staging environment or locally.)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top