Dzinyna Posted May 15, 2016 Share Posted May 15, 2016 Hi,Can any one tell me how to change "-" symbol in the title tag. By default presta gives brand name in the title tag, but I need to change symbol before the brand name to pipe " | " symbol. Now it looks: Some key word - Brand name But I need to show that: Some key word | Brand name Who can help me? Link to comment Share on other sites More sharing options...
shokinro Posted May 15, 2016 Share Posted May 15, 2016 (edited) are you using Prestaashop default theme or paid commercial theme? by default, PrestaShop is instead "-" I think, it is in following file /themes/default-bootstrap/header.tpl you can see the line below for page title is as following <title>{$meta_title|escape:'html':'UTF-8'}</title> $meta_title is generated in file /classes/Meta.php Edited May 17, 2016 by shokinro (see edit history) Link to comment Share on other sites More sharing options...
Dzinyna Posted May 16, 2016 Author Share Posted May 16, 2016 I use paid commercial theme, and I can see the line <title>{$meta_title|escape:'html':'UTF-8'}</title> How can I change that symbol? Link to comment Share on other sites More sharing options...
shokinro Posted May 17, 2016 Share Posted May 17, 2016 The meta title for each page is generated in following file, so you will need to modify the same file or its override class file. /classes/Meta.php Or (recommended) /override//classes/Meta.php For example, for category page public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '') { if (!empty($title)) { $title = ' - '.$title; } ....... // Paginate title if (!empty($row['meta_title'])) { $row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); } else { $row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); } if (!empty($title)) { $row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); } Link to comment Share on other sites More sharing options...
Dzinyna Posted May 17, 2016 Author Share Posted May 17, 2016 I have no such a file meta.php in override/classes/ Link to comment Share on other sites More sharing options...
NemoPS Posted May 18, 2016 Share Posted May 18, 2016 You can just use{$meta_title|replace:'-':'|'|escape:'html':'UTF-8'}Should do it Link to comment Share on other sites More sharing options...
shokinro Posted May 18, 2016 Share Posted May 18, 2016 @Dzinyna thanks @Nemo1, he has given you a better solution. it should be working fine. by the way to reply your following comment I have no such a file meta.php in override/classes/ If that file is not there, you need to create one to extends the core class and override it. Link to comment Share on other sites More sharing options...
Dzinyna Posted May 18, 2016 Author Share Posted May 18, 2016 All right. I found meta.php file on https://sourceforge.net/p/iprestashop/code-0/2/tree/override/classes/Meta.php#l6 where the file is empty. Do I need put jus one line in there from Nemo1 post {$meta_title|replace:'-':'|'|escape:'html':'UTF-8'}. <?php class Meta extends MetaCore { $meta_title|replace:'-':'|'|escape:'html':'UTF-8' } To make it look like that. If yes, I did that, but symbol didn't changed. Sorry for my understanding php. I have jus basic knowledgement. Link to comment Share on other sites More sharing options...
shokinro Posted May 18, 2016 Share Posted May 18, 2016 No, I think you got misunderstood and mixed up. The solution from Nemo1 is following line in file /themes/YourTheme/header.tpl Change from {$meta_title|escape:'html':'UTF-8'} To {$meta_title|replace:'-':'|'|escape:'html':'UTF-8'} 1 Link to comment Share on other sites More sharing options...
Dzinyna Posted May 20, 2016 Author Share Posted May 20, 2016 That was great Thank you so much shokinro and Nemo1 Link to comment Share on other sites More sharing options...
shokinro Posted May 21, 2016 Share Posted May 21, 2016 glad it worked, thanks Nemo1 Link to comment Share on other sites More sharing options...
Dzinyna Posted May 26, 2016 Author Share Posted May 26, 2016 The solution worked. But there I found another issue. I can't put any " - " symbol to the title tag to separate keywords, all " - " is changed to pipe symbol. I need to be changed only the last one before my site name. Not all " - " these symbols. Any solutions? Link to comment Share on other sites More sharing options...
shokinro Posted May 27, 2016 Share Posted May 27, 2016 in that case, you may need to modify the class file Meta.php I mentioned previously. Link to comment Share on other sites More sharing options...
Dzinyna Posted May 30, 2016 Author Share Posted May 30, 2016 As I mentioned few posts ago, that my understanding of PHP is just basics. Can some one help me to create thet meta file? Link to comment Share on other sites More sharing options...
rocky Posted June 1, 2016 Share Posted June 1, 2016 I've tried to create the override for you below based on the code from PrestaShop v1.6.1.5. If you have caching enabled, you may need to clear your cache by going to Advanced Parameters > Performance and then clicking the "Clear cache" button at the top before all the metatitles will update. Note also that the "Layered Navigation" module will override this, causing the " - " to return on category pages. You'll need to disable the "Layered Navigation" module or modify that module to use " | " as well. <?php class Meta extends MetaCore { 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'].' | '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME'); $ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : ''; $ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] : ''; return $ret; } 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'); $cache_id = 'Meta::getCategoryMetas'.(int)$id_category.'-'.(int)$id_lang; if (!Cache::isStored($cache_id)) { 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.')' : '').' | '.Configuration::get('PS_SHOP_NAME'); } else { $row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' | '.Configuration::get('PS_SHOP_NAME'); } if (!empty($title)) { $row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' | '.Configuration::get('PS_SHOP_NAME'); } $result = Meta::completeMetaTags($row, $row['name']); } else { $result = Meta::getHomeMetas($id_lang, $page_name); } Cache::store($cache_id, $result); return $result; } return Cache::retrieve($cache_id); } 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); } 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'].' | '.Configuration::get('PS_SHOP_NAME'); } return Meta::completeMetaTags($row, $row['name']); } return Meta::getHomeMetas($id_lang, $page_name); } 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. ((int)Context::getContext()->shop->id ? ' AND id_shop = '.(int)Context::getContext()->shop->id : ''); if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { $row['meta_title'] = $row['meta_title'].' | '.Configuration::get('PS_SHOP_NAME'); return Meta::completeMetaTags($row, $row['meta_title']); } return Meta::getHomeMetas($id_lang, $page_name); } 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. ((int)Context::getContext()->shop->id ? ' AND id_shop = '.(int)Context::getContext()->shop->id : ''); if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) { $row['meta_title'] = $row['meta_title'].' | '.Configuration::get('PS_SHOP_NAME'); return Meta::completeMetaTags($row, $row['meta_title']); } return Meta::getHomeMetas($id_lang, $page_name); } 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.' - '.Configuration::get('PS_SHOP_NAME'); } 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; } } 1 Link to comment Share on other sites More sharing options...
shokinro Posted June 1, 2016 Share Posted June 1, 2016 @rocky, rock. 1 Link to comment Share on other sites More sharing options...
Dzinyna Posted June 16, 2016 Author Share Posted June 16, 2016 I worked like a charm. Thank you. Link to comment Share on other sites More sharing options...
rocky Posted June 16, 2016 Share Posted June 16, 2016 I'm happy it worked for you. Please edit your first post and add [sOLVED] to the front of the title. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now