How to pass dynamic image path in Twitter Card?

吃可爱长大的小学妹 提交于 2019-12-13 15:14:22

问题


I am using

<?php $image='http://abc.in/def.jpg'; ?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta name="twitter:card" content="summary">
        <meta name="og:image" content="<?php echo $image?>">
        <meta name="og:description" content="<?php echo $description; ?>">
        <meta name="og:title" content="<?php echo $title; ?>">
        <meta name="twitter:url" content="http://keyss.in">
        <meta name="twitter:app:id:iphone" content="">
        <meta name="twitter:app:id:ipad" content="">
        <meta name="twitter:app:id:googleplay" content="">
        <meta name="twitter:app:url:iphone" content="">
        <meta name="twitter:app:url:ipad" content="">
        <meta name="twitter:app:url:googleplay" content="">
    </head>
</html>

code for my Twitter post.

When I pass static content in <meta name="og:image" content="http://abc.in/def.jpg"> image is posted on my Twitter wall, but if I pass variable as <meta name="og:image" content="<?php echo $image?>"> image is not posted on my wall.

How can I pass dynamic variable in image content?


回答1:


The missing semicolon after $image could be the issue (as mentioned in the comments):

    <meta name="og:image" content="<?php echo $image; ?>">
    <meta name="og:description" content="<?php echo $description; ?>">
    <meta name="og:title" content="<?php echo $title; ?>">

Once you've fixed the code, run the Page through the Twitter Card validator to make sure everything appears correctly. It should hopefully give you an idea of what's going wrong.



来源:https://stackoverflow.com/questions/22243526/how-to-pass-dynamic-image-path-in-twitter-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!