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.

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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统