Jump to content

Change " - " to " | " pipe symbol in title tag


Dzinyna

Recommended Posts

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

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 by shokinro (see edit history)
Link to comment
Share on other sites

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

@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

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

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'}
  • Like 1
Link to comment
Share on other sites

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

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;
    }    
}
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...