I have noticed that facebook is having issues with finding relevant text when sharing a blog post manually or via AddThis. The easiest solution seems to be to add a <meta description=... tag in the head of the page. Seems easier said than done though.
I'm using $head_title to set the <meta title=.. tag in the head of the page. Is there another variable available to index.tpl containing the entry body so I can truncate it and insert the meta tag in the head of the page?
If not, any other ideas on how to accomplish this?
Thanks
Clint
Facebook having trouble generating preview when sharing
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Facebook having trouble generating preview when sharing
Have you looked at the html meta tag plugin? See also this blog entry.
=Don=
Re: Facebook having trouble generating preview when sharing
No, somehow I missed that one.
But, it doesn't work. The is due to the way I build the header, and not the fault of the plugin.
I have a header template file from our main website which has placeholders in it for things like the title, some banners and additional CSS. I have a function in index.tpl called DisplayHeader that grabs that template and inserts the relevent info into those placeholders. I pass necessary info from index.tpl to the function and have several bits like this:
then I replace the css placeholder in my header template file with $css
I did edit serendipity_event_metadesc.php and see if something like:would allow me to access $metadescription in index.tpl and pass it to my DisplayHeader function as $params['metadescription']. Didn't seem to work.
If you're at all inclined to assist me, it would be much appreciated.
Thanks
Clint
But, it doesn't work. The is due to the way I build the header, and not the fault of the plugin.
I have a header template file from our main website which has placeholders in it for things like the title, some banners and additional CSS. I have a function in index.tpl called DisplayHeader that grabs that template and inserts the relevent info into those placeholders. I pass necessary info from index.tpl to the function and have several bits like this:
Code: Select all
$css = <<<EOF
<meta name="title" content="{$params['entrytitle']}" />
<link rel="stylesheet" type="text/css" href="{$params['stylesheet']}" />
<link rel="alternate" type="application/rss+xml" title="{$params['title']} RSS feed" href="{$params['baseurl']}{$params['rwprefix']}feeds/index.rss2" />
<link rel="alternate" type="application/x.atom+xml" title="{$blogTitle} Atom feed" href="{$baseurl}{$params['rwprefix']}feeds/atom.xml" />
<script type="text/javascript" src="http://www.kingsnake.com/blog/plugin/ls-js"></script>
EOF;
I did edit serendipity_event_metadesc.php and see if something like:
Code: Select all
$serendipity['smarty']->assign('metadescription','<meta name="description" content="' . htmlspecialchars($meta_description) . '" />' ."\n");
If you're at all inclined to assist me, it would be much appreciated.
Thanks
Clint
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Facebook having trouble generating preview when sharing
Hi!
Your DisplayHeader function could instead access $smarty->get('metadescription') - when the variable is assigned, you can use it. Otherwise you would need to pass {$metadescription} to your {DisplayHeader} smarty function call to have it available as a $param.
HTH,
Garvin
Your DisplayHeader function could instead access $smarty->get('metadescription') - when the variable is assigned, you can use it. Otherwise you would need to pass {$metadescription} to your {DisplayHeader} smarty function call to have it available as a $param.
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Facebook having trouble generating preview when sharing
IMHO I still feel the meta tag plugin is ideal for this... not only does it solve your facebook issue, but allows you to provide individual meta descriptions for each entry that are not just a truncated version of your entry body.
=Don=
Re: Facebook having trouble generating preview when sharing
Don: Yes, your plugin basically does what I need. I'll just need to do some minor modifications to get the data it generates in a format I can use.
Thanks for the help Garvin and Don.
Clint
Thanks for the help Garvin and Don.
Clint
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Facebook having trouble generating preview when sharing
For the record, its not "my" plugin.... I simply made a minor modification to it a few years ago. Hope everything works out for you!perlnerd wrote:Don: Yes, your plugin basically does what I need. I'll just need to do some minor modifications to get the data it generates in a format I can use.
Thanks for the help Garvin and Don.
Clint
=Don=
Re: Facebook having trouble generating preview when sharing
My solution won't apply to too many people but just incase:
I split my DisplayHeader function into two functions. One to process and display everything in my remote header file up to my {css} placeholder and one to display everything after my {css} placeholder.
This lets me insert {serendipity_hookPlugin hook="frontend_header"} and whatever else I need between these functions. This gets the live search .js and meta description in the right place.
I also made a new copy of the meta tag plugin and modified extract_description() to truncate the description text on a word boundary.
I split my DisplayHeader function into two functions. One to process and display everything in my remote header file up to my {css} placeholder and one to display everything after my {css} placeholder.
This lets me insert {serendipity_hookPlugin hook="frontend_header"} and whatever else I need between these functions. This gets the live search .js and meta description in the right place.
I also made a new copy of the meta tag plugin and modified extract_description() to truncate the description text on a word boundary.
Code: Select all
$text = strip_tags($text);
$text = substr($text,0,250);
$i = strrpos($text," ");
$title = substr($text,0,$i) . "...";