Jump to content

[SOLVED] facebook og:title and og:description to be modified?


outlet.ee

Recommended Posts

In this post https://www.prestashop.com/forums/topic/209268-facebook-og-meta-image/ it says how to implement the og:image and it works fine. 

I need the title and description to be customized and include the product price /old price and some translations from the product.tpl to the title or description. By default it uses the meta title and meta description. I tried to use 

{$product->name}
{convertPrice price=$productPrice}
{if $productPriceWithoutReduction > $productPrice}{convertPrice price=$productPriceWithoutReduction}{/if} in the header.tpl but only the product name is displayed. Also tried to insert the meta og: tags to product.tpl without luck.

Is there an easy way to achieve this?

Edited by outlet.ee
solved (see edit history)
Link to comment
Share on other sites

Solved it myself via phpmyadmin. Added 2 columns to _product_lang: og_title and og_description. Then added 2 lines to classes/meta.php function getHomeMetas:

	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['og_title'] = (isset($metas['og_title']) && $metas['og_title']) ? $metas['og_title'] : '';
		$ret['og_description'] = (isset($metas['og_description']) && $metas['og_description']) ? $metas['og_description'] : '';
		$ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : '';
		$ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] :  '';
		return $ret;
	}

And changed the getProductMetas:

	public static function getProductMetas($id_product, $id_lang, $page_name)
	{
		$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`, `og_title`, `og_description`
				FROM `'._DB_PREFIX_.'product` p
				LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
				'.Shop::addSqlAssociation('product', 'p').'
				WHERE pl.id_lang = '.(int)$id_lang.'
					AND pl.id_product = '.(int)$id_product.'
					AND product_shop.act........

And last, added 2 lined to header.tpl:

	<meta property="og:title" content="{$og_title}" />
	<meta property="og:description" content="{$og_description}" />

This also requires the 2 newly added columns in _product_lang to be filled with data of course. I use cron to automatically fill them and update the prices in the title/description etc.

Also solved the image ratio issue for facebook sharing. I use this script to crop and fit into the 1200x630 px required by facebook: https://github.com/JamesHeinrich/phpThumb , see the last posts and compare to the older ones: https://www.facebook.com/nordoutlet/

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

ben de uğraştım ama olmadı https://www.bebegentoptan.com help please ?

 

$metas = Meta::getMetaByPage($page_name, $id_lang);
        $ret['meta_title'] = (isset($metas['title']) && $metas['title']) ? $metas['title'] : '';
        $ret['og_image'] = (isset($metas['og_image']) && $metas['og_image']) ? $metas['og_image'] : '';
        $ret['og_title'] = (isset($metas['og_title']) && $metas['og_title']) ? $metas['og_title'] : '';
        $ret['og_description'] = (isset($metas['og_description']) && $metas['og_description']) ? $metas['og_description'] : '';
        $ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : '';
        $ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] :  '';

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