如何在“单页”上使用元标记用于社交分享按钮

时间:2013-11-07 16:37:32

标签: php html facebook wordpress meta-tags

我有一个wordpress“单页”,上面有不同的帖子,不需要重新加载。当您单击帖子名称而不重新加载整个页面时,会加载一个帖子。

所有帖子都有个人ID&虽然subURL。每个帖子还有facebook,twitter,google +,linkedin和xing的分享按钮。

我想为共享提供有关用户想要分享的个人帖子的信息,例如ID,图片,一些文字内容等。

这是我的分享按钮看起来像atm:

    <div class="share-twitter"> 
<a href="https://twitter.com/share?url=http://example.de/%23/?p=<?php the_id();?>/<?php the_title();?>" class="twitter-share-button" target="_blank"><img src="exampleimg.jpg"></a>
 </div> 

现在我在另一篇关于stackoverflow的文章中读到,我应该使用meta标签为它们提供信息。

这就是我试图这样做的方式:

<!-- for Google -->
<meta name="description" content="<?php the_content();?>" />
<meta name="keywords" content="app" />

<meta name="author" content="<?php the_author();?>" />
<meta name="copyright" content="corporate name" />
<meta name="application-name" content="<?php the_title();?>" />

<!-- for Facebook -->          
<meta property="og:title" content="<?php the_title();?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="imgexample.png" />
<meta property="og:url" content="http://example.de/%23/?p=<?php the_id();?>/<?php the_title();?>" />
<meta property="og:description" content="<?php the_content();?>" />

<!-- for Twitter -->          
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="<?php the_title();?>" />
<meta name="twitter:description" content="<?php the_content();?>" />
<meta name="twitter:image" content="imgexample.png" />

嗯,我现在的实际问题是我添加的元标记没有任何改变。链接URL像以前一样正确提供,因为我已经使用href执行此操作,但它仍然使用页面的随机img,没有提供内容或我在元标记上提供的任何其他内容...

为什么这不起作用的任何线索?

1 个答案:

答案 0 :(得分:0)

试试这个:

<php if(is_single()) { ?>
  <meta property="og:image" content="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); ?>" />
<?php } else { ?>
  <meta property="og:image" content="imgexample.png" />