Active
Project:
Open Graph meta tags
Version:
7.x-1.3
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
22 May 2012 at 09:20 UTC
Updated:
3 Apr 2013 at 09:18 UTC
Hello.
In order to avoid a sentence or word cutting when creating "og: description" from the node body, I suggest to replace call to function drupal_substr() with call to text_summary(): line 137 in file opengraph_meta.common.inc:
$ret[self::DESCRIPTION] = !empty($body) ? drupal_substr(strip_tags($body),0,200) : $node->title;
replace with:
$ret[self::DESCRIPTION] = !empty($body) ? text_summary(strip_tags($body),NULL,200) : $node->title;
In this way we will get a nice description, rather than half of a sentence, or in a middle of the word truncated phrase.
Example:
drupal_substr():
"Our foam yoga blocks are a simple tool that will help you ease into difficult poses by strengthening, stretching and aligning your body without strain. Yoga blocks also help to ensure that you practic"
text_summary():
"Our foam yoga blocks are a simple tool that will help you ease into difficult poses by strengthening, stretching and aligning your body without strain."
Comments
Comment #1
erik seifert commentedComment #2
sgdev commentedI would agree with this as well. I would also suggest performing a PHP "trim" to remove spaces I occasionally see at the front of the og:description content and allowing the user to select if they want to use the $node->body or $node->teaser for their description. In most situations, the teaser more than meets the need and provides a nice, neat description.
Comment #3
sgdev commented@erikseifert: does it make sense to do that on a node_load, or in the template preprocess? We do something similar on the theme_preprocess_page to avoid running extra code every time a node_load is done (which in Drupal is often).
Edit: Well the module does it on the nodeapi hook... if staying true to what the module is trying to do it's probably the right place.
Comment #4
erik seifert commentedNormally node load should be cached. So there is no problem to do this in node_load hook.
@see entity_load
If you want to change the functionality from website to website it could go to the theme layer.
A really better approach could be this:
Set a default value for Meta Field with tokens ;-)
Like:
[node:summary]
Comment #5
racinggrinner commentedThanks erikseifert for the useful snippet.
I have modified it to assign the og:description to a custom field which appears within specific content types.
This is useful for existing sites which have a custom teaser field (for example) and the field is preferred to the node body for the og:description.