Jump to content

Individual meta tags per page


Recommended Posts

i've found some vars i can use in the header.tpl:

{$page_name}

and like that i can see the category ID:

{if $smarty.get.id_category}
   {$id_category = $smarty.get.id_category}
{else}
   {$id_category = $product_id_category}
{/if}

 

only thing i did not yet achieve is getting the product description...

question is, how can i get the var {$product} in my header.tpl? if it would be there, i could take this one {$product->description_short} and put it as meta description tag.

Edited by creation-handicap (see edit history)
Link to comment
Share on other sites

What version of PrestaShop are you using? I just checked my PrestaShop v1.6.1.5 test site and it already uses the product's short description as the meta description if none is specified. It's on lines 261-262 of classes/Meta.php:

            if (empty($row['meta_description'])) {
                $row['meta_description'] = strip_tags($row['description_short']);
Link to comment
Share on other sites

In that case, you'll have to create override/classes/FrontController.php with the following:

<?php

class FrontController extends FrontControllerCore
{
    public function displayHeader()
    {
        parent::displayHeader();

        if (Tools::getValue('controller') == 'product' && (int)Tools::getValue('id_product')) {
            $product = new Product((int)Tools::getValue('id_product'), false, (int)Tools::getValue('id_lang'));

            if (Validate::isLoadedObject($product)) {
                self::$smarty->assign('meta_description', $product->description_short);   
            }
        }
    }
}

This should override the {$meta_description} variable in header.tpl with the product's short description if it is available. I haven't tested this code though, so you'll have to test it yourself.

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