Jump to content

Whats name of meta description variable


eljuanan

Recommended Posts

Hi Eljuanan,

You can do this in the back office.

If you're using Prestashop 1.4 head to Back Office > Preferences > SEO & URLs

If you're using Prestashop 1.3 or below, head to Back Office > Preferences > Meta Tags

You'll see a table listing pages from your store, click to Edit your index.php. You'll be able to change your META Titles, Descriptions and Keywords here!

Hope that helps,

Mark

Link to comment
Share on other sites

The Tools class has the method for this.

In /classes/Tools.php line 568

/**
   * Get meta tages for a given page
   *
   * @param integer $id_lang Language id
   * @return array Meta tags
   */
   public static function getMetaTags($id_lang, $page_name)
   {
       global $maintenance;

       if (!(isset($maintenance) AND (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))))
       {
            /* Products specifics meta tags */
           if ($id_product = self::getValue('id_product'))
           {
               $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
               SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`
               FROM `'._DB_PREFIX_.'product` p
               LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
               WHERE pl.id_lang = '.(int)($id_lang).' AND pl.id_product = '.(int)($id_product).' AND p.active = 1');
               if ($row)
               {
                   if (empty($row['meta_description']))
                       $row['meta_description'] = strip_tags($row['description_short']);
                   return self::completeMetaTags($row, $row['name']);
               }
           }

           /* Categories specifics meta tags */
           elseif ($id_category = self::getValue('id_category'))
           {
               $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
               SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
               FROM `'._DB_PREFIX_.'category_lang`
               WHERE id_lang = '.(int)($id_lang).' AND id_category = '.(int)($id_category));
               if ($row)
               {
                   if (empty($row['meta_description']))
                       $row['meta_description'] = strip_tags($row['description']);
                   return self::completeMetaTags($row, $row['name']);
               }
           }

           /* Manufacturers specifics meta tags */
           elseif ($id_manufacturer = self::getValue('id_manufacturer'))
           {
               $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
               SELECT `meta_title`, `meta_description`, `meta_keywords`
               FROM `'._DB_PREFIX_.'manufacturer_lang`
               WHERE id_lang = '.(int)($id_lang).' AND id_manufacturer = '.(int)($id_manufacturer));
               if ($row)
               {
                   if (empty($row['meta_description']))
                       $row['meta_description'] = strip_tags($row['meta_description']);
                   $row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
                   return self::completeMetaTags($row, $row['meta_title']);
               }
           }

           /* Suppliers specifics meta tags */
           elseif ($id_supplier = self::getValue('id_supplier'))
           {
               $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
               SELECT `meta_title`, `meta_description`, `meta_keywords`
               FROM `'._DB_PREFIX_.'supplier_lang`
               WHERE id_lang = '.(int)($id_lang).' AND id_supplier = '.(int)($id_supplier));
               if ($row)
               {
                   if (empty($row['meta_description']))
                       $row['meta_description'] = strip_tags($row['meta_description']);
                   $row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
                   return self::completeMetaTags($row, $row['meta_title']);
               }
           }

           /* CMS specifics meta tags */
           elseif ($id_cms = self::getValue('id_cms'))
           {
               $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
               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)
               {
                   $row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
                   return self::completeMetaTags($row, $row['meta_title']);
               }
           }
       }

       /* Default meta tags */
       return self::getHomeMetaTags($id_lang, $page_name);
   }



So you would call this using

global $cookie;
Tools::getMetaTags($cookie->id_lang, 'index');



If you know you only want the index however, you can skip the middle man and call the Tools:: getHomeMetaTags method directly with:

global $cookie;
Tools::getHomeMetaTags($cookie->id_lang, 'index');

Link to comment
Share on other sites

That would return an array as follows (with your details as the values):

Array ( [meta_title] => Presta Shop [meta_description] => Shop powered by PrestaShop [meta_keywords] => shop, prestashop )



So you could use:

global $cookie;
$meta = Tools::getHomeMetaTags($cookie->id_lang, 'index');
$description = $meta['meta_description'];



You could then 'assign' this into your smarty .tpl, or use it in your module .php as you wish!

Mark

Link to comment
Share on other sites

Sorry but it not works, im in back-end, its posible problem language???
how to access to active language in back end
$meta = Tools::getHomeMetaTags($lang, 'index');
$metadescription = $meta['meta_description'];

thanks

Link to comment
Share on other sites

Does the $lang variable you have set store a value?

Make sure you have set global $cookie; within your function in the module, and exchange $lang to $cookie->id_lang.

So for example, if in your module you're using the the right column hook, you would need:

public function hookRightColumn($params){
       global $cookie;
               $meta = Tools::getHomeMetaTags($cookie->id_lang, ‘index’);
               $metadescription = $meta[‘meta_description’];
}



You need to specify the global $cookie line or you'll get errors.

Where are you trying to use this?

Mark

Link to comment
Share on other sites

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...