简体   繁体   English

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

[英]How to use meta tags for social share buttons on a “single-page”

I got a wordpress "single-page" with different posts on it, that doesnt need to reload. 我有一个wordpress“单页”,上面有不同的帖子,不需要重新加载。 A post is loaded in when you click on a post name without reloading the whole page. 当您单击帖子名称时,将加载一个帖子,而无需重新加载整个页面。

All posts have a individual ID & subURL though. 不过,所有帖子都有单独的ID和subURL。 Each post also has share buttons for facebook, twitter, google+, linkedin and xing. 每个帖子还具有用于Facebook,Twitter,Google +,linkedin和Xing的共享按钮。

I want to provide the shares with the information about the individual post the user wants to share, for example ID, image, some text content and so on. 我想为共享提供有关用户想要共享的各个帖子的信息,例如ID,图像,一些文本内容等。

This is what my share buttons look like atm: 这是我的共享按钮看起来像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> 

Now I read in another article here on stackoverflow that i should use meta tags to give them the information. 现在,我在这里阅读了另一篇有关stackoverflow的文章,我应该使用元标记为它们提供信息。

This is how i tried to do this: 这就是我试图做到的方式:

<!-- 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" />

Well, my actual problem now is that the meta tags I added change nothing. 好吧,我现在的实际问题是我添加的meta标签什么都没改变。 the link URL is provided correctly as before, cause i already do this with href, but it still uses a random img of the page, no content provided or anything else I provided over the meta tags... 链接URL像以前一样正确提供,因为我已经使用href做到了,但是它仍然使用页面的随机img,未提供内容或我在meta标签上提供的任何其他内容...

Any clues why this doesnt work? 任何线索为什么这不起作用?

Try this: 尝试这个:

<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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM