Hai thẻ Title và Description có vai trò rất quan trọng trong quá trình SEO Website. Và trong Magento cũng hỗ trợ cho bạn nhập hai thẻ này khi tạo mới một sản phẩm hoặc danh mục.
Lời khuyên: Từ khóa nên xuất hiện trong Title và Description.
Tuy nhiên để tiết kiệm thời gian khi đăng sản phẩm, các bạn có thể set tự động tạo thẻ Title và Description.
Để làm được điều đó các bạn tiến hành chèn file: app/design/frontend/[theme đang dùng]/template/page/html/head.phtml đoạn code sau:
<?php
$desc = strip_tags(trim($this->getDescription()));
$kw = trim($this->getKeywords());
$title = strip_tags(trim($this->getTitle())).’ | vntechmart.com’;
if (Mage::registry(‘current_product’)) {
$categoryIds = Mage::registry(‘current_product’)->getCategoryIds();
if(count($categoryIds) ){
$firstCategoryId = $categoryIds[1];
$category = Mage::getModel(‘catalog/category’)->load($firstCategoryId);
}
$desc = Mage::registry(‘current_product’)->getName(). ‘ ‘. strip_tags(Mage::registry(‘current_product’)->getShortDescription());
$desc = substr($desc, 0, 150);
if($title = Mage::getStoreConfig(‘design/head/default_title’) || $title == Mage::registry(‘current_product’)->getDescription())
{
if(strtolower(substr($desc, 0, strlen($title))) !== strtolower($title))
{
$title =$category->getName().’ ‘.Mage::registry(‘current_product’)->getName().’ | vntechmart.com’;
}
}
if(empty($kw) || $kw == Mage::getStoreConfig(‘design/head/default_keywords’))
{
$kw = Mage::registry(‘current_product’)->getName().’,’.$kw;
}
}
if (Mage::registry(‘current_category’))
{
if(empty($desc) || $desc == Mage::getStoreConfig(‘design/head/default_description’))
{
$desc = $this->getTitle(). ‘ ‘. strip_tags(str_replace(“<br />”,”, “,substr(Mage::registry(‘current_category’)->getDescription(), 0, strpos(Mage::registry(‘current_category’)->getDescription(), ‘.’)+1)));
$desc = substr($desc, 0, 150);
}
if(empty($kw) || $kw == Mage::getStoreConfig(‘design/head/default_keywords’))
{
$kw = $title.’,’.$kw;
}
}
echo ‘<title>’.$title.'</title>’;
echo ‘<meta name=”description” content=”‘.$desc.'” />’;
echo ‘<meta name=”keywords” content=”‘.$kw.'” />’;
?>
Chúc các bạn thành công!