<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>プラグイン | hgrs&#039;s Blog</title>
	<atom:link href="/archives/tag/%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>文字好きエンジニアの技術メモ</description>
	<lastBuildDate>Sat, 18 May 2019 21:08:02 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.1</generator>

<image>
	<url>/wp-content/uploads/2019/05/cropped-port_512-32x32.png</url>
	<title>プラグイン | hgrs&#039;s Blog</title>
	<link>/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPressの記事上にアイキャッチをJavaScriptで自動挿入する</title>
		<link>/archives/207.html</link>
					<comments>/archives/207.html#respond</comments>
		
		<dc:creator><![CDATA[hgrs]]></dc:creator>
		<pubDate>Sun, 19 May 2019 01:12:35 +0000</pubDate>
				<category><![CDATA[技術メモ]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[プラグイン]]></category>
		<guid isPermaLink="false">/?p=207</guid>

					<description><![CDATA[はじめに 僕の使ってるテーマNishikiでは投稿ページにアイキャッチが表示されません。なので記事の...]]></description>
										<content:encoded><![CDATA[<h2>はじめに</h2>
<p>僕の使ってるテーマ<a href="https://ja.wordpress.org/themes/nishiki/">Nishiki</a>では投稿ページにアイキャッチが表示されません。なので記事の上にアイキャッチが表示されるように変更してみました、<strong>JavaScript</strong>で。PHPじゃなくて、<strong>JavaScript</strong>で。</p>
<h2>なんでJavaScript？</h2>
<p>WordPressといえばPHPですよね。確かに、アイキャッチの追加はテーマのPHPをいじれば追加することができます。</p>
<p>でも僕はまだブログを始めたばかりで、今後テーマを変えてしまうかもしれないので、あまりテーマに依存した書き方をしたくなかったのです。</p>
<p>そのため、別の方法で追加する必要がありました。そこで記事の上下にHTMLを挿入できるプラグインを使用して実現しました。</p>
<p>HTMLが書けるということは<code>&lt;script&gt;&lt;/script&gt;</code>タグを利用してJavaScriptが書けます。なのでJavaScriptで実現しています。</p>
<h2>事前準備</h2>
<p>記事の上下にHTMLを追加するプラグインを入れます。</p>
<p><a href="https://ja.wordpress.org/plugins/pryc-wp-add-custom-content-to-bottom-of-post/">PRyC WP: Add custom content to post and page (top/bottom)</a></p>
<h2>追加コードの記入</h2>
<p>プラグインの設定から記事上のコードに以下のコードを書き加えます（操作は図を参照）。</p>
<p>注意点としては、一行目の<code>&lt;img&gt;</code>タグの<code>src</code>は自分の好きな読み込み中の画像を設定しましょう。</p>
<pre><code class="language-javascript">&lt;img name=&quot;top_ogp_image&quot; src=&quot;https://example.com/path/to/loading.png&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    var metas = document.head.children;
    for(var i=0; i&lt;metas.length; i++){
        var property = metas[i].getAttribute(&#039;property&#039;);
        if(property === &#039;og:image&#039;){
            var imagePath = metas[i].getAttribute(&#039;content&#039;);
            document.top_ogp_image.src = imagePath;
        }
    }
&lt;/script&gt;</code></pre>
<p><img decoding="async" src="/wp-content/uploads/2019/05/2019-05-19-00.01.03-blog.hgrs_.me-3024d1e39b5c.png" alt="JavaScriptのアイキャッチ" /></p>
<h2>仕組みの解説</h2>
<p>JavaScriptからDOMを使用し、<code>&lt;meata&gt;</code>タグに設定されているOGP画像を読み取ってきます。</p>
<p>ただ特定の<code>&lt;meta&gt;</code>タグを一発で取ってくることができないため、まず<code>document.head.children</code>を利用し、<code>&lt;head&gt;&lt;/head&gt;</code>の全ての子要素を取ってきます。そこからOGP画像（<code>property</code>が<code>og:image</code>になっているもの）を抜き出します。</p>
<p>そしてOGP画像で読み込んでいる画像をあらかじめ用意した<code>&lt;img&gt;</code>タグの<code>src</code>として割り当てます。</p>
<p>こうすることで、JavaScriptを使ってアイキャッチ画像の自動挿入を実現できます。</p>
<h2>メリット</h2>
<h3>テーマに依存しない</h3>
<p>さっきも書きましたね。テーマを変えたりした時にわざわざ移行の必要がありません。単純に記事上下にHTMLを書き加えるプラグインなのでカスタマイズ性も高いです。</p>
<h3>一括管理ができる</h3>
<p>例えば「やっぱりアイキャッチ消そ」「表示サイズ/場所を変えよ」といったことが一括で操作できます。まあ、これはPHPでも同じですが…</p>
<p>ただ、このプラグインではIDを指定することで特定の記事には表示しないといった指定ができるのは良い点ですね。</p>
<h2>デメリット</h2>
<h3>読み込みが発生する</h3>
<p>JavaScriptで書いているので、クライアントサイド（ブラウザ）で画像の割り当てが実行されます。そのため、サーバサイドのPHPと違って、ページを読み込んだ後に画像を探すので、タイムラグが生じます。このタイムラグが画像読み込みの遅延の原因です。</p>
<h2>おわりに</h2>
<p>ちょっと特殊な方法でアイキャッチを指定しましたが、自由度が高いので良いですね。いつ表示を消すかわかりませんが笑。</p>
<p><del>ほんとはPHPが嫌いなので書きたくなかっただけ。</del></p>
]]></content:encoded>
					
					<wfw:commentRss>/archives/207.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPressに入れたプラグインの紹介</title>
		<link>/archives/53.html</link>
					<comments>/archives/53.html#respond</comments>
		
		<dc:creator><![CDATA[hgrs]]></dc:creator>
		<pubDate>Mon, 29 Apr 2019 15:39:20 +0000</pubDate>
				<category><![CDATA[技術メモ]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[カスタムテーマ]]></category>
		<category><![CDATA[プラグイン]]></category>
		<guid isPermaLink="false">/?p=53</guid>

					<description><![CDATA[はじめに WordPressを使い始めたばかりなので、手探りですが、自分なりに良さそうなプラグインを...]]></description>
										<content:encoded><![CDATA[<h2>はじめに</h2>
<p>WordPressを使い始めたばかりなので、手探りですが、自分なりに良さそうなプラグインを入れたので、紹介していきたいと思います。</p>
<h2>プラグイン一覧</h2>
<h3><a href="https://ja.wordpress.org/plugins/really-simple-ssl/">Really Simple SSL</a></h3>
<p>常時SSL化するためのプラグインです。<code>http</code>なんて忘れて、<code>https</code>にしましょう。</p>
<p>プラグイン自体は特に設定などもなく、有効化し使用すると常時SSL化できます。シンプルでいいですね。</p>
<h3><a href="https://ja.wordpress.org/plugins/wp-githuber-md/">WP Githuber MD</a></h3>
<p>記事をMarkdownで書くためのプラグインです。こちらは個別で記事を書いたので、詳細は<a href="/20190429230413">こちら</a>を。</p>
<p>1番入れてよかったと思ってるプラグインです。</p>
<h3><a href="https://ja.wordpress.org/plugins/wp-user-avatar/">WP User Avatar</a></h3>
<p>ユーザアイコンを設定するためのプラグインです。特にこれにした理由はありませんが、検索の上の方に出てきたので使いました。別に困ってません。</p>
<h3><a href="https://ja.wordpress.org/plugins/all-in-one-seo-pack/">All In One SEO Pack</a></h3>
<p>SEO対策のためのプラグインです。僕の使ってるテーマはOGPをいい感じに設定してくれなかったり、Googleアナリティクスを使いたかったりしたので、入れました。</p>
<h3><a href="https://ja.wordpress.org/plugins/pryc-wp-add-custom-content-to-bottom-of-post/">PRyC WP: Add custom content to post and page (top/bottom)</a></h3>
<p>記事の上下に定型文（HTML, Javascript）を埋め込むことができるプラグインです。僕の使っているテーマは良い感じに記事のページでアイキャッチが表示されないので、こちらを使い無理やり実装しました。</p>
<h3><a href="https://ja.wordpress.org/plugins/wordpress-popular-posts/">WordPress Popular Posts</a></h3>
<p>サイドバーに「人気記事」を追加したかったのでこのプラグインを導入しました。人気の集計はプラグインを導入後から計測されるので注意です。</p>
<h3><a href="https://ja.wordpress.org/plugins/q2w3-fixed-widget/">Q2W3 Fixed Widget for WordPress</a></h3>
<p>サイドバーを固定したかったのでこれを入れました。PCの人はわかると思いますが、サイドバーが一定のところでスクロールをやめてくれます。</p>
<h3><a href="https://ja.wordpress.org/plugins/header-footer/">Head, Footer and Post Injections</a></h3>
<p>HTMLの<code>&lt;head&gt;&lt;/head&gt;</code>に要素を書き加えられます。また<code>&lt;body&gt;&lt;/body&gt;</code>の直後/直前にもコードを書き加えられますがその機能は使ってません。</p>
<h2>【番外編】カスタムテーマ: <a href="https://ja.wordpress.org/themes/nishiki/">Nishiki</a></h2>
<p>プラグインではないですが、使用しているカスタムテーマです。正直あまり気に入ってはいませんが、しっくりくるものを見つける/作るまではこれを使っていこうと思います。</p>
<h2>おわりに</h2>
<p>なんかオススメのプラグイン/テーマがあったら教えてください。</p>
]]></content:encoded>
					
					<wfw:commentRss>/archives/53.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WP Githuber MDでいい感じにWordPressでMarkdownを使う</title>
		<link>/archives/36.html</link>
					<comments>/archives/36.html#respond</comments>
		
		<dc:creator><![CDATA[hgrs]]></dc:creator>
		<pubDate>Mon, 29 Apr 2019 14:04:13 +0000</pubDate>
				<category><![CDATA[技術メモ]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[プラグイン]]></category>
		<guid isPermaLink="false">/?p=36</guid>

					<description><![CDATA[はじめに この記事を書くのに使われているのがWP Githuber MDです。名前からしてわかるよう...]]></description>
										<content:encoded><![CDATA[<h2>はじめに</h2>
<p>この記事を書くのに使われているのが<a href="https://wordpress.org/plugins/wp-githuber-md/">WP Githuber MD</a>です。名前からしてわかるように、GitHubでのMarkdownを再現した感じのプラグインです。</p>
<p>編集画面はこんな感じです。<br />
<img decoding="async" src="/wp-content/uploads/2019/04/1cdbc32d50799d7508b42ce24be70451.png" alt="編集画面" /></p>
<h2>使いやすさ</h2>
<p>普段からMarkdownを書くことがある人は、特に迷うことなく使えるし、すごくいい感じです。</p>
<p>しかも、追加モジュールとして、コードのシンタックスハイライト（Prism.js）を設定できたり、TeX（KaTeX）が使えたりします。</p>
<p>シンタックスハイライト例</p>
<pre><code class="language-python">from fontParts.world import OpenFont

def open_font(path):
    font = OpenFont(path)
    return font

test_font = open_font(&#039;test.otf&#039;)</code></pre>
<p>Tex例<br />
<code class="language-katex katex-inline">B > \frac{1}{n} {\sum \limits ^{n}_{i=1}}x_i</code></p>
<h2>おわりに</h2>
<p>普通に使いやすいので、これからの記事は、このプラグインを使って書こうと思います。</p>
]]></content:encoded>
					
					<wfw:commentRss>/archives/36.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
