Advertisement:

Author Topic: Add meta description to item page  (Read 3021 times)

code monkey

  • Full Member
  • ***
  • Posts: 204
Add meta description to item page
« on: March 27, 2011, 11:17:19 pm »
Use the same function as for search and home page listings. It is called osc_item_description()... but I suggest customizing it as such...

oc-includes/osclass/helpers/hItems.php

Code: [Select]
function osc_item_description_extract($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
$extract = trim(preg_replace('/\s+/', ' ', strip_tags(osc_item_field("s_description", $locale))));
if ( strlen($extract) > 175 )
$extract = substr($extract, 0, 172) . '...';
return $extract;
}

This will take the item's description, remove all HTML, and strip all new line characters. You end up with a blob of text about 175 characters in length. Now you just need to drop it into the meta description tag.

oc-content/themes/modern/item.php

Between the <head></head> section, add...
Code: [Select]
<!-- Search Engines -->
<meta name="description" content="<?php echo preg_replace('/"/'''osc_item_description() ); ?>" /> 

See: http://bit.ly/es1pUw (right-click > view-source)
« Last Edit: March 27, 2011, 11:23:21 pm by code monkey »

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: Add meta description to item page
« Reply #1 on: April 05, 2011, 05:39:03 pm »
It has been fixed in develop branch! Here you can see the changes: https://github.com/osclass/OSClass/commit/4d1ca8679c255fd052511254361b16696439d3fe