Using Open Graph in a CMS

kendra

BANNED
Joined
Aug 12, 2009
Messages
535
Reaction score
339
In case anyone else wants to use the open graph meta tags in a CMS I am going to post how to do it. (I made a post asking how to do this, but figured it out myself and thought it worth sharing).

I am using this in Zen Cart and Wordpress, each require a slightly different setup - but should be the same on other platforms, maybe some one else could post the specifics.

This allows you to automatically generate dynamic Facebook meta data - so that each page you stick a 'LIKE' button on will have its own title, description and URL in the FB meta tags.


Zen Cart

I am not sure if this is template dependant as all my sites use the same template and I haven't tested further. But it works just fine for me.

Place this in your header file along with all other META data.
Code:
<meta property="og:title" content="<?php echo META_TAG_TITLE; ?>"/>

<meta property="og:description" content="<?php echo META_TAG_DESCRIPTION; ?>" />

<meta property="og:url" content="<?php echo curPageURL(); ?>"/>
Add this to your header to allow the URL to be echoed.
Code:
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
Wordpress

Add this to your header file:
Code:
<?php if ( is_single() ) {
echo '<meta property="og:title" content="' . get_the_title(get_the_ID()) . '" />';
echo '<meta property="og:url" content="' . get_permalink() . '" />';
}
?>
 
open graph protocol willn't help you much until the new search engine rollout, its the open graph api where the money is.
 
I assume that the open graph api will be using the same meta code though?

Of is nothing known about it at all regarding all that?
 
Back
Top