
wordpress入口主题
您想将 Twitter 卡添加到您的 WordPress 网站吗? Twitter 卡使您可以将富媒体附加到链接到您的内容的推文中。这与在 Facebook 上共享链接非常相似,Facebook 会自动显示页面内容的预览、标题、摘要和缩略图。在本文中,我们将向您展示如何在 WordPress 中添加 Twitter 卡。
您想将 Twitter 卡添加到您的 WordPress 网站吗? Twitter 卡允许您将富媒体附加到链接到您的内容的推文中。这与在 Facebook 上共享链接非常相似,Facebook 会自动显示带有页面内容的标题、摘要和缩略图的预览。在本文中,我们将向您展示如何在 WordPress 中添加 Twitter 卡。

Twitter卡如何工作? (How Does Twitter Cards Work?)
When your tweet has a link to a site that has twitter cards enabled, there is an option to view summary. Whenever another user clicks on the tweet, they will see this summary like the screenshot below. You can see the live example by going to our 推特页面.
当您的推文具有指向启用了推特卡的网站的链接时,将提供查看摘要的选项。 每当其他用户单击该推文时,他们都会看到此摘要,如下面的屏幕截图所示。 您可以转到我们的推特页面,查看实时示例。

拥有 Twitter 卡的最大优点是,它可以通过内容归因增加关注您的 Twitter 帐户的人数。人们经常在推特上发布您的链接,但没有给您适当的归属。
拥有 Twitter 卡的最大优势是,它可以通过内容归因增加关注你的 Twitter 帐户的人数。人们经常发布您的链接而没有给您适当的归属。
我们从一些受欢迎的内容策展人那里特别注意到了这一点。他们将通过 @wpbeginner 或 RT @wpbeginner 来推特我们的文章,而无需任何内容。这是他们的权利,但是当其他人用其他人的属性转发您的内容时,我们/您作为发布者会特别错过。
我们特别从一些受欢迎的内容策展人那里注意到了这一点。他们不会通过@wpbeginner 或RT @wpbeginner 发送任何推文。这是他们的权利,但我们/您作为发布者尤其会错过其他人使用其他人的属性重新发布您的内容的情况。
例如,@syedbalkhi 转发了 @wpbeginner 的帖子,但没有注明出处,而其他人则转发了 @syedbalkhi。那么查看这些转发的用户更有可能关注 @syedbalkhi 而不是 @wpbeginner。
例如,@syedbalkhi 转发了 @wpbeginner 的帖子,但没有注明出处,而其他人则转发了 @syedbalkhi。查看这些转发的用户更有可能关注 @syedbalkhi 而不是 @wpbeginner。
内容策展人通常这样做是为了保持推文长度较短并确保他们自己的推文得到转发。使用 Twitter 卡,这个问题就得到了解决,因为您可以从每条提及您文章的推文中获得对您网站的认可。注意:我们不会针对内容策展人。这是 140 个字符限制的缺陷,Twitter 正在通过 Twitter 卡帮助修复它。
内容管理员经常这样做是为了保持推文长度较短并确保自己的转发。有了 Twitter 卡,这个问题就得到了解决,因为您可以从每条提及您文章的推文中获得对您网站的认可。注意:我们不选择内容管理者。这是一个有 140 个字符限制的缺陷,Twitter 正在使用 Twitter Cards 来修复它。
例如,当安妮在推特上发布我们的文章时,她没有提到@wpbeginner。但由于我们的 Twitter 卡集成,我们获得了充分的信誉和曝光度。请注意它还有一个一键关注按钮。
例如,当安妮在推特上谈论我们的文章时,她没有提到@wpbeginner。但由于我们的 Twitter 卡集成,我们获得了充分的可信度和曝光度。请注意,它还有一个“点击关注”按钮。

现在您已经了解了 Twitter 卡的好处,让我们看看如何在 WordPress 中实现。
现在您已经了解了 Twitter 卡片的好处,让我们看看如何在 WordPress 中实现它们。
如何在WordPress中添加Twitter卡 (How to Add Twitter Cards in WordPress)
在 WordPress 中添加 Twitter 卡有两种方法。我们来看看他们两个。
在 WordPress 中添加 Twitter 卡的方法有两种。让我们看看他们两个。
方法一:Yoast SEO插件
方法一:Yoast SEO插件
If you are using WordPress SEO 由 Yoast 提供 plugin, then you are in luck. Yoast has built-in integration for twitter cards, so turning it on is a matter of few clicks.
如果您正在使用酵母插件使用WordPress 搜索引擎优化 ,那么您很幸运。 Yoast具有Twitter卡的内置集成,因此只需单击几下即可将其打开。
只需转到 Yoast SEO 设置页面的“社交”页面即可。输入您的 Twitter 用户名并保存更改。
只需进入 Yoast SEO 设置页面的社交页面即可。输入您的 Twitter 用户名并保存更改。

之后单击 Twitter 选项卡。在 Twitter 选项卡下,您需要选中添加 Twitter 卡元数据框。选择要选择的默认卡类型。您可以选择显示摘要或使用大图像显示摘要。
之后,单击 Twitter 选项卡。在“Twitter”选项卡下,您需要选中“添加 Twitter 卡元数据”复选框。选择默认卡类型进行选择。您可以选择显示摘要或将摘要显示为大图像。

Next thing you need to do is go to 用户 » 我的个人资料 page. You will see a new field under Contact Info for your twitter username. Enter your twitter username there.
接下来,您需要进入“ 用户”»“我的个人资料”页面。 您将在Twitter Info的“联系信息”下看到一个新字段。 在此处输入您的Twitter用户名。
如果您正在运行一个多作者网站,请建议您的作者在其个人资料中完成此部分。这样,每个特定作者的工作也会得到认可。请参阅下面的示例:
如果您运行的是多作者网站,建议您的作者在其个人资料中填写此部分。这样,每个特定作者的工作也会得到认可。请参阅以下示例:

这就是您已成功将 Twitter 卡元标记添加到您的 WordPress 网站的全部内容。
这就是成功将 Twitter 卡元标记添加到 WordPress 网站所需的全部内容。
这种方法是迄今为止最简单的方法。由于我们在所有网站上都使用 Yoast 的 WordPress SEO,因此我们正在使用这种方法。
这种方法是迄今为止最简单的。由于我们在所有网站上都使用 Yoast 的 WordPress SEO,因此我们正在使用这种方法。
方法2:自己硬编码
方法2:自己硬编码
This method requires adding code to your theme or child theme files. Simply open the header.php file and add this code just before the </head>
tag.
此方法需要将代码添加到主题或子主题文件中。 只需打开header.php文件并在</head>
标记之前添加此代码即可。
<?php
#twitter cards hack
if(is_single() || is_page()) {
$twitter_url = get_permalink();
$twitter_title = get_the_title();
$twitter_desc = get_the_excerpt();
$twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
$twitter_thumb = $twitter_thumbs[0];
if(!$twitter_thumb) {
$twitter_thumb = 'http://www.gravatar.com/avatar/8eb9ee80d39f13cbbad56da88ef3a6ee?rating=PG&size=75';
}
$twitter_name = str_replace('@', '', get_the_author_meta('twitter'));
?>
<meta name="twitter:card" value="summary" />
<meta name="twitter:url" value="<?php echo $twitter_url; ?>" />
<meta name="twitter:title" value="<?php echo $twitter_title; ?>" />
<meta name="twitter:description" value="<?php echo $twitter_desc; ?>" />
<meta name="twitter:image" value="<?php echo $twitter_thumb; ?>" />
<meta name="twitter:site" value="@libdemvoice" />
<?
if($twitter_name) {
?>
<meta name="twitter:creator" value="@<?php echo $twitter_name; ?>" />
<?
}
}
?>
资料来源:Ryan Cullen @artesea
资料来源:Ryan Cullen @artesea
如果您不知道如何使用 PHP 或在使用方法 2 时遇到问题,请使用方法 1。
如果您不知道如何使用 PHP 或者对方法 2 有问题,请使用方法 1。
最后一步:测试和验证 (Final Step: Test and Validate)
在 WordPress 网站的链接开始显示 Twitter 卡片之前,您需要首先在 Twitter 卡片验证器中检查它。
在 WordPress 网站上的链接开始显示 Twitter 卡片之前,您需要首先在 Twitter 卡片验证器中检查它们。
Simply head over to the 卡片验证器 page on Twitter developers website. Enter URL of any post from your WordPress site and click on preview card button.
只需转到Twitter开发人员网站上的卡片验证器页面即可。 输入您WordPress网站中任何帖子的URL,然后单击预览卡按钮。

Twitter 将向您显示 Twitter 卡的预览。
Twitter 将向您显示 Twitter 卡的预览。
更新: Previously you had to apply for participation in the Twitter Cards. However, Twitter has implemented a system that automatically whitelists domains when you test them with the validator or just share a URL on Twitter.
更新:以前,您必须申请加入Twitter卡。 但是,Twitter实施了一个系统,当您使用验证程序测试域或仅在Twitter上共享URL时,该域会自动将域列入白名单。
We hope this article helped you add Twitter cards in WordPress. You may also want to see our list of the 10 个最受欢迎的 Twitter 黑客和 WordPress 插件.
我们希望本文能帮助您在WordPress中添加Twitter卡。 您可能还想查看我们10 个最受欢迎的 Twitter 黑客和 WordPress 插件列表。
If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特和Facebook上找到我们。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-twitter-cards-in-wordpress/
wordpress入口主题