在当前主题的 functions.php
末尾加入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| function showThumbnail($widget) { $random = 'https://bing-phi.vercel.app/'; $attach = $widget->attachments(1)->attachment; $pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
if (preg_match_all($pattern, $widget->content, $thumbUrl)) { echo $thumbUrl[1][0]; } else if ($attach->isImage) { echo $attach->url; } else { echo $random; } }
|
编辑当前主题的 header.php
,在 <head>
内加入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!-- 首页的 meta,自行修改内容 --> <?php if($this->is('index')): ?> <meta property="og:url" content="https://v2try.com/"/> <meta property="og:type" content="blog"/> <meta property="og:title" content="We To Try"/> <meta property="og:image" content="<?php showThumbnail($this); ?>"/> <meta property="og:author" content="v2try"/> <meta property="og:site_name" content="We To Try"/> <meta property="og:description" content="网络日志"/> <meta property="og:locale:alternate" content="zh_CN"/> <?php endif; ?>
<!-- 其它页面的 meta ,不需要修改 --> <?php if($this->is('post')||$this->is('page')): ?> <meta property="og:url" content="<?php $this->permalink(); ?>"/> <meta property="og:type" content="blog"/> <meta property="og:title" content="<?php $this->title(); ?>"/> <meta property="og:image" content="<?php showThumbnail($this); ?>"/> <meta property="og:author" content="<?php $this->author(); ?>"/> <meta property="og:site_name" content="<?php $this->options->title(); ?>"/> <meta property="og:description" content="<?php $this->description(); ?>"/> <meta property="og:locale:alternate" content="zh_CN"/> <?php endif; ?>
|
Typecho 为站点添加 Open Graph 标签