this is actually a very complicated question so i'll start to explain it.
I have a CMS called 'FusionCMS' which uses Codeigniter.
It Dynamically Generate the pages ( like news ) so they looks like domain.com/news/1 or /2 etc.. but that folders actually doesn't really exist.
There is header.tpl file in view file which contains the meta tags.
I make a PHP script to select special text from database to be as og tags.
what i means with oh tags are the facebook meta tags exp : og:title - og:description.
I want them to be selected depends on the page link ( exp if it's /news/11 ) than to select the ID 11 from database which will have title and content which will be what i need.
This are the codes ( PHP is missing the selection from URL and some modifications ). The TPL file is very big so i'll just put some of it.
PHP
if(isset($_GET['post'])) {
$postid = $_GET['post'];
$conn = mysqli_connect("127.0.0.1","root","ascent","fusioncms");
$stmt = $conn->prepare("SELECT title, description FROM news WHERE id = ?");
$stmt->bind_param("i", $postid);
$stmt->execute();
$stmt->bind_result($title, $message);
$stmt->store_result();
if($stmt->num_rows > 0) {
while($stmt->fetch()) {
echo "<meta name='og:title' content='".$title."'>";
echo "<meta name='og:description' content='".$message."'>";
}
}
}else{
echo "<meta name='og:title' content='Example Page for JadaDev'>";
echo "<meta name='og:description' content='Some random description'>";
}
This is the TPL file ( header.tpl )
<!-- Custom Scripts -->
<meta property="og:title" content="{$title}"/>
<meta property="og:type" content="website" />
<meta property="og:url" content="{$path}"/>
<meta property="og:image" content="http://127.0.0.1/application/themes/default/images/tam.png"/>
<meta property="og:site_name" content="حزب تيار المحبة"/>
<meta property="fb:app_id" content="2217370698541973" />
<meta property="fb:admins" content="John.Evenetcha"/>
<meta property="og:description" content="{$title}"/>
<!-- End of Custom -->