Reputation: 47945
I'm trying to make a link to my website and facebook, putting some meta data on it! My target is to manage this data :
<meta property="og:title" content="MY_PAGE_TITLE" />
<meta property="og:description" content="MY_DESCRIPTION_TEXT" />
Unfortunatly, my web application (on PHP) is not well structured, and I haven't define a correct MVC! It is very procedural, so the infos that I should put on these meta tag are extracted, from database, after the rendering of the main html header section.
So, what I tried is this :
<script type="text/javascript">
$('head').append("<meta property=\"og:title\" content=\"MY_PAGE_TITLE\" />");
$('head').append("<meta property=\"og:description\" content=\"MY_DESCRIPTION_TEXT\" />");
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<fb:like href="<?=$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]?>" send="false" layout="button_count" width="130" show_faces="false"></fb:like>
But in fact, it doesnt works! I mean, append meta tag on the head and than try render it.
Do you know some strategies to do it? I'll avoid the option on insert directly them on the head, because, as I says, the text I'd like to insert is get after the head section (due to a wrong organization of the website).
I believe in another solution, hope you know one!
Upvotes: 0
Views: 2270
Reputation: 12244
Sad but no other way than to change your structure. The reason for the og: tags not being processed even with your javascript is that facebook doesn't render the javascript. It just asks for the page and reads the OG tags from the top just like static HTML would be.
Your only option is to change your structure and load your content before the output. You don't need to change to MVC for that, juste loading your content BEFORE the head will save you heaps of work and still work...
Upvotes: 5