【狂人論壇】

 找回密碼
 註冊
搜索

WordPress 網站不使用外掛就能顯示 og tags 的方法

5512

主題

1萬

金錢

184

積分

不來恩

積分
184
brian 發表於 2014-3-8 15:53 | 顯示全部樓層 |閱讀模式
Facebook Open Graph Meta Tags

這個好像是自己亂湊出來的? 不知道是不是很完整正確,總之還勉強能用。
使用方法:
直接把下面代碼寫在布景主題的 header.php 檔案中的適當位置,不用另外安裝什麼外掛,一樣堪用...
  1. <meta property="og:locale" content="zh_TW"/>
  2. <meta property="og:type" content="article"/>
  3. <meta property="og:title" content="<?php wp_title( '|', true, 'right' ); ?>"/>
  4. <meta property="og:description" content="<?php
  5.         global $post;
  6.         if ( is_singular() ) {
  7.         if ( $post->post_excerpt ) {
  8.         $post_excerpt = $post->post_excerpt;
  9.         } else {
  10.         $post_excerpt = trim( str_replace( "\r\n", ' ', strip_tags( $post->post_content ) ) );
  11.         }
  12.         $description = mb_substr( $post_excerpt, 0, 150, 'UTF-8' );
  13.         $description .= ( mb_strlen( $post_excerpt, 'UTF-8' ) > 150 ) ? '...' : '';
  14.         printf('%s', $description);
  15.         }
  16.         ?>"/>
  17. <meta property="og:url" content="http://<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>"/>
  18. <meta property="og:site_name" content="重灌狂人"/>
複製代碼



您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|聯絡站長|重灌狂人|狂人論壇

GMT+8, 2024-4-24 17:04

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回復 返回頂部 返回列表