ブログを作るにあたって、アクセスを集めるためには、はてなブックマーク(はてブ)からのアクセスアップがとても効果的とのこと。
そこで、WordPressで各記事の上下に、SNSのアイコンを表示させる方法を紹介する。
以下の、各SNSボタンのリンクに飛び、好きなテーマを決めてカスタマイズする。
Twitter
Facebook
Google+
はてな
以下の記事の通り、single.phpを使う。
参考:ブログに必須!はてなブックマーク ボタンをWordPressに設置する手順【プラグイン未使用Ver】
twitterとhatenaのボタンを記事の上下に設置した。
筆者の例では以下、赤文字の通り。
// single.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php /** * The template for displaying all single posts and attachments * * *略* */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <!-- twitter--> <span style="color: #ff0000;">ここにコードを挿入</span> <!-- hatena--> <span style="color: #ff0000;">ここにコードを挿入</span> <?php // Start the loop. while ( have_posts() ) : the_post(); // Include the single post content template. get_template_part( 'template-parts/content', 'single' ); *略* // End of the loop. endwhile; ?> <!-- twitter--> <span style="color: #ff0000;">ここにコードを挿入</span> <!-- hatena--> <span style="color: #ff0000;">ここにコードを挿入</span> </main><!-- .site-main --> <?php get_sidebar( 'content-bottom' ); ?> </div><!-- .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?> |
single.phpは、他のthemesファイルのfunctions.phpなどと同じく、子テーマを使って実装した。
参考:wordpress子テーマの作り方!style.css・各テンプレートファイル・function.php の設定手順
Tweet
