简体   繁体   English

如何在 Joomla 中为每篇文章添加不同的 OG 和 twitter 元标签

[英]How to add different OG and twitter meta tags for each article in Joomla

How can I use OG and Twitter meta tags in Joomla pages.如何在 Joomla 页面中使用 OG 和 Twitter 元标记。 Is there any plugin which creates additional fields in the article editor under 'publishing'tab ?是否有任何插件可以在“发布”选项卡下的文章编辑器中创建其他字段? Thanks in advance.提前致谢。

From what I have investigated, Facebook does automatically place all description, title and picture in its place.根据我的调查,Facebook 确实会自动将所有描述、标题和图片放在它的位置。 Twitter does not.推特没有。 You need to added manually.您需要手动添加。 I had the same problem fixed with this code.我用这段代码解决了同样的问题。 I was trying to get Twitter to add my link just as facebook does automatically but had to investigate the CARD Validator here https://cards-dev.twitter.com/validator ... The way I have it working on Joomla 3.9.11 is adding this code in the head of my template default.php ... I was able to properly add the title, the description and the right picture, usually the first one on the article.我试图让 Twitter 添加我的链接,就像 facebook 自动做的那样,但不得不在这里调查 CARD Validator https://cards-dev.twitter.com/validator ...我在 Joomla 3.9.11 上工作的方式正在我的模板 default.php 的头部添加这段代码......我能够正确添加标题、描述和正确的图片,通常是文章的第一个。

<head>
<?php 
//Added for TWITTER
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    $theArticle = $article->get("title");
    $theImages = $article->get("images");   
    $pictures = json_decode($theImages); // Split the parameters apart
    $timage= "http://yourdomain.com/".$pictures->{'image_intro'};
}
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta name="twitter:title" content="'.mb_strimwidth(strip_tags($theArticle),0,225, " ...").'"=""/>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="yoursite">
<meta name="twitter:creator" content="yourcreator">
<meta name="twitter:url" content="'.JURI::current().'">
<meta name="twitter:description" content="'.mb_strimwidth(strip_tags($doc->getMetaData( 'description' )),0,225, " ...").'"=""/>
<meta name="twitter:image" content="'.$timage.'">
');
?>
<!-- This is what is already on Joomla Headers -->
    <jdoc:include type="head" />
    <?php $this->loadBlock('head') ?>
</head>

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

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