In this paper, we will write step by step tutorial about deleting shop name from page title. It's one way to enhance / change SEO of your shop. We also assume that if you've come here you probably already know something about "SEO" and editing prestashop template (.tpl) files. If not - don't worry - we will clearly describe each steps in this paper. All steps described in this tutorial was made in PrestaShop 1.5.2 but in most cases - it will works in older versions too. Just follow the steps and check code.
What you will need?
Ready? Let's start the show :)
All of the works we will do by using "override" feature in prestashop. What does it mean? It mean that all of works we will do by overriding Meta class. For do that you must open override/clases/Meta.php file, you've got there empty class, like code below:
1 2 3 4 5 6 |
<?php class Meta extends MetaCore { // we will put overrided functions here } |
We will paste modified original functions to this class, right from original Meta.php class located in classes/Meta.php file. Ok, now when you know something about editing and overriding, we can start.
As we say, we must do some modifications in original Meta class functions. What we have to do? We must change or delete Configuration::get('PS_SHOP_NAME') parameter from functions. Read code in steps carefully, because it's different for each functions.
1. Removing shop name from homepage meta title tag in Prestashop
Code below is already edited for displaying page title without shop name:
1 2 3 4 5 6 7 8 |
public static function getHomeMetas($id_lang, $page_name) { $metas = Meta::getMetaByPage($page_name, $id_lang); $ret['meta_title'] = (isset($metas['title']) && $metas['title']) ? $metas['title'] : ''; $ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : ''; $ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] : ''; return $ret; } |
Paste this function to overrided class in override/clases/Meta.php file
2. Removing shop name from category pages meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '') { if (!empty($title)) $title = ' - '.$title; $page_number = (int)Tools::getValue('p'); $sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description` FROM `'._DB_PREFIX_.'category_lang` cl WHERE cl.`id_lang` = '.(int)$id_lang.' AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl'); if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { if (empty($row['meta_description'])) $row['meta_description'] = strip_tags($row['description']); // Paginate title if (!empty($row['meta_title'])) $row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : ''); else $row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : ''); if (!empty($title)) $row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : ''); return Meta::completeMetaTags($row, $row['name']); } return Meta::getHomeMetas($id_lang, $page_name); } |
Paste this function to overrided class in override/clases/Meta.php file
3. Removing shop name from manufacturer pages meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static function getManufacturerMetas($id_manufacturer, $id_lang, $page_name) { $page_number = (int)Tools::getValue('p'); $sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords` FROM `'._DB_PREFIX_.'manufacturer_lang` ml LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (ml.`id_manufacturer` = m.`id_manufacturer`) WHERE ml.id_lang = '.(int)$id_lang.' AND ml.id_manufacturer = '.(int)$id_manufacturer; if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { if (empty($row['meta_description'])) $row['meta_description'] = strip_tags($row['meta_description']); $row['meta_title'] = ($row['meta_title'] ? $row['meta_title'] : $row['name']).(!empty($page_number) ? ' ('.$page_number.')' : ''); //$row['meta_title'] .= ' - '.Configuration::get('PS_SHOP_NAME'); return Meta::completeMetaTags($row, $row['meta_title']); } return Meta::getHomeMetas($id_lang, $page_name); } |
Paste this function to overrided class in override/clases/Meta.php file
4. Removing shop name from supplier pages meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public static function getSupplierMetas($id_supplier, $id_lang, $page_name) { $sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords` FROM `'._DB_PREFIX_.'supplier_lang` sl LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (sl.`id_supplier` = s.`id_supplier`) WHERE sl.id_lang = '.(int)$id_lang.' AND sl.id_supplier = '.(int)$id_supplier; if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { if (empty($row['meta_description'])) $row['meta_description'] = strip_tags($row['meta_description']); if (!empty($row['meta_title'])) $row['meta_title'] = $row['meta_title']; return Meta::completeMetaTags($row, $row['name']); } return Meta::getHomeMetas($id_lang, $page_name); } |
Paste this function to overrided class in override/clases/Meta.php file
5. Removing shop name from CMS pages meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public static function getCmsMetas($id_cms, $id_lang, $page_name) { $sql = 'SELECT `meta_title`, `meta_description`, `meta_keywords` FROM `'._DB_PREFIX_.'cms_lang` WHERE id_lang = '.(int)$id_lang.' AND id_cms = '.(int)$id_cms; if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { $row['meta_title'] = $row['meta_title']; return Meta::completeMetaTags($row, $row['meta_title']); } return Meta::getHomeMetas($id_lang, $page_name); } |
Paste this function to overrided class in override/clases/Meta.php file
6. Removing shop name from CMS category pages meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public static function getCmsCategoryMetas($id_cms_category, $id_lang, $page_name) { $sql = 'SELECT `meta_title`, `meta_description`, `meta_keywords` FROM `'._DB_PREFIX_.'cms_category_lang` WHERE id_lang = '.(int)$id_lang.' AND id_cms_category = '.(int)$id_cms_category; if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { $row['meta_title'] = $row['meta_title']; return Meta::completeMetaTags($row, $row['meta_title']); } return Meta::getHomeMetas($id_lang, $page_name); } |
Paste this function to overrided class in override/clases/Meta.php file
7. Removing shop name from complete meta title tag in Prestashop
Code below is already edited for displaying title without shop name:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public static function completeMetaTags($meta_tags, $default_value, Context $context = null) { if (!$context) $context = Context::getContext(); if (empty($meta_tags['meta_title'])) $meta_tags['meta_title'] = $default_value; if (empty($meta_tags['meta_description'])) $meta_tags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', $context->language->id) ? Configuration::get('PS_META_DESCRIPTION', $context->language->id) : ''; if (empty($meta_tags['meta_keywords'])) $meta_tags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', $context->language->id) ? Configuration::get('PS_META_KEYWORDS', $context->language->id) : ''; return $meta_tags; } |
Paste this function to overrided class in override/clases/Meta.php file
Summary
You can download overrided meta class file. If you've got any questions or problems, feel free to comment this article and we will help you.