如何在WordPress首页和文章页添加OG协议标签

2022年11月17日 / 网站源码 / 没有评论 / 1,363次

前面提到的《知更鸟主题《Begin》seo社会化分享优化》知识针对知更鸟的主题,但是放在其他主题上会出错,龙哥专门研究了下,可以通过在header.php里添加如下通用代码来实现og协议。

  1. <?php if ( is_home() ) { ?>
  2. <meta property="og:title" content="龙哥 (Long.Ge) &laquo; 官方网站" />
  3. <meta property="og:description" content="龙哥个人博客,用文字记录生活" />
  4. <meta property="og:url" content="https://long.ge/" />
  5. <meta property="og:locale" content="zh_CN" />
  6. <meta property="og:image" content="https://long.ge/favicon.png" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:site_name" content="龙哥 (Long.Ge) - 官方网站" />
  9. <?php } ?>
  10. <?php if (is_singular()) { ?>
  11. <meta property="og:locale" content="zh_CN" />
  12. <meta property="og:type" content="acticle">
  13. <meta property="og:title" content="<?php the_title();?>">
  14. <meta property="og:site_name" content="<?php bloginfo('name');?>">
  15. <meta property="og:description" content="<?php the_excerpt();?>">
  16. <meta property="og:url" content="<?php the_permalink();?>"/>
  17. <meta property="og:image" content="https://long.ge/favicon.png">
  18. <?php } ?>