Tự động tạo thẻ Title, Description trên Magento

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!

 

 

5/5 - (1 bình chọn)

Hosting LiteSpeed SSD giá rẻ

admin has written 106 articles

Các bạn cần hỗ trợ hoặc kết bạn vui lòng liên hệ:
Skype: lephonghau37
Email: lephonghau@gmail.com
Zalo: 0908 077 994

Hosting Hawk Host

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>