need a php guru help me out with dynamically adding og tags

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
glens1234
Joomla! Explorer
Joomla! Explorer
Posts: 299
Joined: Tue Feb 19, 2008 8:13 pm

need a php guru help me out with dynamically adding og tags

Post by glens1234 » Thu Mar 14, 2013 5:57 am

Hi.

My client wants specific images to be shared on facebook. I have tried using a plugin to do this but i need to home page og tags to be different from the rest. Now, im not php guy so i dont really know what im doing. Here is what i have so far...

Code: Select all

 <?php
$url = JURI::current();
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$doc = $doc->getElementById('content');  
$images = $doc->getElementsByTagName('img');

foreach ($images as $image) {
$src = $image->getAttribute('src');
echo '<meta property="og:image" content="$src\n" />';
} 
?>
However, when i try on my local host i get nothing. By that i mean the page just hangs. Is this because the file_get_contents() function is trying to pull to pull the whole page in?

I have no idea.
Your advice will be greatly appreciated.

Locked

Return to “Joomla! 2.5 Coding”