Twitter dynamic meta tag deosnt work using PHP


I want to implement dynamic twitter meta tag. So Every page when i try to share twitter will have their each specify image and title.

i tried set dynamic title, and image but it doesnt work. image and title didnt change dynamic.

I use this code to get data from database


$viral = new Viral();

$id = $viral->escape_string($_GET['id']);

$result = $viral->getData("SELECT * FROM preview WHERE id=$id");

foreach ($result as $res) {
  $title = $res['title'];
  $promoted = $res['promoted'];
  $photo = $res['file'];

below twitter meta tag which i tried to use

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="<?php echo   (($title == "" || $title == NULL) ? "My website" : $title)  ?>"/> 
<meta name="twitter:description" content="My description">
<meta name="twitter:image" content="<?php echo   (($photo == "" || $photo == NULL) ? "upload/default-640.png" : $photo)  ?>" />

Is it need specify size and resolution for image ?

Any missing code ?


The Twitter cards infrastructure will cache the card information for a specific URL for up to 7 days. There is no programmatic way to change this, so dynamic behaviour like this is currently not possible. There is more information in the troubleshooting section of the cards documentation


Hi @andypiper

Thanks for your reply, i just want to know how about platform like wordpress, or another platform that i saw when i tried shared their own article on twitter, their image thumbnail appear my tweet.

How to get it work ?