ブログの設定いじった。その備忘録。

2017年9月14日WordPress,技術,雑多

この記事は2016年4月28日に書かれたものです。ご注意ください。

昨日・今日でブログをいじったので、そのメモ。
わりと使える内容だったり。

ソースコード掲載設定

https://39life.net/highlightjs/

「Crayon Syntax Highlighter」から「highlight.js」へ変更。
いじった箇所は以下。
simplicity2-child\header.php

<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

ブログカード設定

http://nelog.jp/wordpress-hatena-blog-card

外部リンクもブログカードになるよう設定。記事にあった内容をそのまま流用。
simplicity2-child\functions.php

//本文中のURLをはてなブログカードタグに変更する
function url_to_hatena_blog_card($the_content) {
  if ( is_singular() ) {//投稿ページもしくは固定ページのとき
    //1行にURLのみが期待されている行(URL)を全て$mに取得
    $res = preg_match_all('/^(<p>)?(<a.+?>)?https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+(<\/a>)?(<\/p>)?(<br ? \/>)?$/im', $the_content,$m);
    //マッチしたURL一つ一つをループしてカードを作成
    foreach ($m[0] as $match) {
      $url = strip_tags($match);//URL
      
//      //サイトの内部リンクは処理しない場合(Simplicity対策)
//      preg_match( '/https?:\/\/(.+?)\//i', admin_url(), $r );//自サイトのドメイン取得
//      if ( strpos( $url, $r[1] ) ) {
//        continue ;
//      }
      
      //取得した情報からブログカードのHTMLタグを作成
      $tag = '<iframe class="hatenablogcard" src="http://hatenablog.com/embed?url='.$url.'" frameborder="0" scrolling="no"></iframe>';
      //本文中のURLをブログカードタグで置換
      $the_content = preg_replace('{'.preg_quote($match).'}', $tag , $the_content, 1);
    }
  }
  return $the_content;//置換後のコンテンツを返す
}
add_filter('the_content','url_to_hatena_blog_card');//本文表示をフック

→Simplicityの設定をよく見たら外部リンクも有効化する設定がありました…。そのため上記コードは削除済みです。

管理者用 PV設定

http://wp-simplicity.com/admin-pv/

一応これも設定。CSSも設定済み。
simplicity2-child\style.css

/* WordPress Popular Posts */
.admin-pv {
    font-size: 12px;
}

軽量化

プラグインだとか設定。

以上。