dpdkqls6399 2015-06-03 22:32
浏览 38
已采纳

仅为主页设置og标签

i have a problem with og tags. i added on my template index a string like

<meta property="og:image" content="http://www.example.com/facebook.jpg" /> 

to fix an image for the site when shared on facebook because otherwise strange images where chosen by facebook. But this conflicts with all my blog articles pages when shared on facebook. And the og tag image override the blog image when my article is shared. I need help to set the og tags in the template index.php to work only for my homepage.

They suggested me something like

if($currentPage == 'home' || $currentPage == 'article'){
codeSampleToAddSocialShare()
}

but i really can't make it my myself, i don't know where to put the code and if it's correct or just an example. Thanks for your help

  • 写回答

1条回答 默认 最新

  • douzhaolu4839 2015-06-04 15:56
    关注

    If you want to edit the template directly, here is a conditional check you can do to see if the homepage is being displayed:

    (Assuming you are using Joomla 2.5 or 3.x. See this link for more info & other versions)

    <?php
      $app = JFactory::getApplication();
      $menu = $app->getMenu();
      if ($menu->getActive() == $menu->getDefault()) {
          echo '<meta property="og:image" content="http://www.example.com/facebook.jpg" /> ';
      }
    ?>
    

    Ideally, you would create a plugin to add the meta tag to your HTML HEAD so updates to your template do not overwrite your changes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C