I friend asked me if i can write something in PHP. I'm new to websripting languages. I need the URL from the page and write the correct meta tag for it. I also want to have the html element in a meta tag for the open graph protocol...
<head>
<title>test</title>
<?php
$meta_close = '"/>'."
"."\t";
//get url from page, found code on stackoverflow
$link = "http//www.$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$escaped_link = htmlspecialchars($link, ENT_QUOTES, 'UTF-8');
$meta_url1 = '<meta property="og:url" content="';
//get page <title> element, found on stackoverflow
$pattern = "/<title>(.*?)<\/title>/";
preg_match($pattern, $string, $match);
$meta_title1 ='<meta property="og:title" content="Zee-Online|';
echo "".$meta_url1.$escaped_link.$meta_close;
echo "".$meta_title1.$match[1].$meta_close; //problem here?
?>
</head>
This is the result:
<head>
<title>test</title>
<meta property="og:url" content="http//www.woodworking-creations.be/test.php"/>
<meta property="og:title" content="Zee-Online |"/>
In the title property, this script doesn't append the title (in this case "test") Should have this
<head>
<title>test</title>
<meta property="og:url" content="http//www.woodworking-creations.be/test.php"/>
<meta property="og:title" content="Zee-Online | test"/>
And another problem, and that's why i try this: "Zee-online" is a local news site. If we share an article, it's alwas the wrong picture. I think i need to get all the images on the page, and add a meta tag for each of them? How to? Facebook always shows a picture of one of our volunteers. We have added a meta tag for the image, so now always or logo shows up. But we want to be able to show one of the images in the article, if available.
(Zee-online is on www.zee-online.be, but i'm not the administrator, so i tried it on my own website with a test page)