WordPress カスタムしたこと メモ

WordPress カスタムしたこと メモ

2017/08/16 自分の誤操作でDBが全消去、Wordpress関連の設定も全て消えてしまいました。これを機にサーバーをCORESERVERへ移転、Hatena Blogに避難していた記事を元に少しづつ更新していきます。

復旧

URL 転送

Redirectionプラグイン

アフィリエイト関連

カエレバCSS

アマゾンのアフィリエイトリンクを見せる方法にしようしています。

/*--------------------------------------
ヨメレバ・カエレバ(レスポンシブ)
--------------------------------------*/
.booklink-box, .kaerebalink-box{
padding:25px;
margin-bottom: 10px;
border:solid #CCC;
overflow: hidden;
font-size:small;
}
.booklink-image, .kaerebalink-image{
margin:0 15px 0 0;
float:left;
min-width: 160px;
text-align: center;
}
.booklink-image img, .kaerebalink-image img{
margin:0 auto;
text-align:center;
}
.booklink-info, .kaerebalink-info{
margin:0;
line-height:120%;
overflow: hidden;
}
.booklink-name, .kaerebalink-name{
margin-bottom:24px;
line-height:1.5em;
}
.booklink-powered-date, .kaerebalink-powered-date{
font-size:8px;
margin-top:10px;
font-family:verdana;
line-height:120%;
}
.booklink-detail, .kaerebalink-detail{font-size: 12px;}
.booklink-powered-date, .kaerebalink-detail{margin-bottom:15px;}
.booklink-link2, .kaerebalink-link1{margin-top:10px;}
.booklink-link2 a,
.kaerebalink-link1 a{
width:30%;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
display:inline-block;
margin:5px 2px 0 0;
padding:10px 1px;
text-align:center;
float:left;
text-decoration:none;
font-weight:800;
text-shadow:1px 1px 1px #dcdcdc;
font-size:12px;
color: #fff !important;
}
.booklink-link2 a:hover,
.kaerebalink-link1 a:hover{opacity: 0.6;}
.booklink-link2 a:active
.kaerebalink-link1 a:active{
position:relative;
top:1px;
}
/*ボタンを変えるときはここから*/
.shoplinkamazon a{color:#000000 !important;border: 1px solid #000000 !important;}
.shoplinkrakuten a{color:#c20004 !important;border: 1px solid #c20004 !important;}
.shoplinkkindle a{color:#007dcd !important;border: 1px solid #007dcd !important;}
.shoplinkkakakucom a{color:#314995 !important;border: 1px solid #314995;}
.shoplinkyahoo a{color:#7b0099 !important;border: 1px solid #7b0099 !important;}
/*ここまでを変更*/
.shoplinkyahoo img{display:none;}
.shoplinkyahoo a{font-size:10px;}
.booklink-footer{display: none;}

@media screen and (max-width: 680px) {
.booklink-box, .kaerebalink-box{padding:15px;}
.booklink-image, .kaerebalink-image{
width: 100px !important;
min-width: initial;
}
.booklink-name > a, .kaerebalink-name > a{
font-size: 15px;
font-weight: bold;
}
.booklink-name, .kaerebalink-name{margin-bottom:12px;}
.booklink-powered-date, .kaerebalink-powered-date{margin-top:5px;}
.booklink-link2 a,
.kaerebalink-link1 a{
width:calc(100% - 4px);
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
margin: 2px 0px;
padding:10px 0px;
}
}

 

プラグイン
フォント置き換え:Easy Google Fonts

Easy Google Fontsで簡単にフォントを設定

SNSシェアボタン:Share Buttons by AddThis

Share Buttons by AddThis

人気記事まとめ作成:WordPress Popular Posts

WordPress Popular Posts で人気記事を表示する方法

wordpress-popular-posts/style/wpp.cssへ追記

margin-right:10px;
border-bottom:1px dashed #666;
ソースコードを表示:Crayon Syntax Highlighter

Crayon Syntax Highlighter – ソースコードを記事上で綺麗に表示できるWordPressプラグイン

目次自動生成:Table of Contents Plus

Table of Contents Plus – 記事の目次を自動生成できるWordPressプラグイン

目次の自動表示プラグインTable of Contents Plusの使い方と設定

カスタムCSS

/*table of contents plus*/
/*--------------------------------------
  TOC+
--------------------------------------*/
#toc_container {
	display: block !important;
	width: 100% !important;
	background: #f5f5f5;
	border: 1px solid #cccccc;
	font-size: 100%;
	box-sizing: border-box;
	line-height: 1;
	font-weight: normal;
	margin: 0px;
	padding: 1em 2em;
	text-align: left;
}
 
#toc_container .toc_title {
	text-align: left;
	border-bottom: 0px solid #CCCCCC;
		font-size: 130%;
	font-weight: normal;
	margin 0px;
	padding: 0px;

}
 
#toc_container ul {
    list-style: none;
    margin-bottom: 0px;
	text-align: left;
}
 
#toc_container ul li {
    margin-bottom: 0px;
    padding-left: 0;
    text-indent: 0;
	font-weight: normal;
}
 
#toc_container ul a {
	display: block;
	text-decoration: none;
	color: #444;
	border-bottom: 0px dotted #fff;
	font-weight: normal;
}
 
#toc_container .toc_list > li > a {
	border-bottom: 1px solid #CCCCCC;
	font-size: 100%;
	padding-bottom: 5px;
	font-weight: normal;
}
 
#toc_container ul ul {
	padding: 1em 0 0em 0em;
}
 
#toc_container li {
	margin-bottom: px;
	padding-bottom: 1em;
}


/* --------related---------- */
h3.related-title {
  font-size: 18px;
  margin-bottom: 8px;
  padding: 10px;
  line-height: 25px;
}
 
.related{
  padding:15px;}
  
.related ul{
  margin:0;
  padding:0;
  list-style:none;}
  
.related li a{
  display:block;
  padding:5px;
  color:0066cc;
  font-size:14px;
  text-decoration:none;}
  
.related li a:hover{
  background-color:#cccccc;}
  
.related ul:after {
  content:"";
  display:block;
  clear:both;}
  
.related li {
  height: 200px;
  float: left;
  width: 150px;
  padding-right: 20px;
  overflow: hidden;
}
 
.related img {
  max-height:150px;
  float:left;
  width:150px;
  padding-right: 20px;
  margin-bottom: 10px;
}
.related-title{
  margin-bottom:15px;
  margin-top:15px;
  font-size:18px;
  padding-left:10px;
}
  
.related{
  margin-bottom:15px;
  border:1px solid #cccccc;
}
p.no-related {
 padding-left: 15px;
 margin-bottom: 15px;
}

 

セキュリティ対策
ユーザー名をadminから独自名へ変更
wp-config.phpのアクセス制限 .htaccessへ追記
<files wp-config.php>

order allow,deny

deny from all

</files>
wp-config,phpのパーミッションを「400」へ

http://design-plus1.com/tcd-w/2015/09/security.html

http://viral-community.com/wordpress/wordpress-security-1298/

アフィリエイト
Google Search Console

https://www.google.com/webmasters/tools/home?hl=ja

headerへトラッキングコードを追記

スマホ用:Amazonアソシエイト Mobile popover

https://affiliate.amazon.co.jp/home/tools/mobilepopover/faq

Google Adsense Page-level Ad

https://support.google.com/adsense/answer/6245304?hl=en

Head, Footer and Post Injections

https://www.iscle.com/web-it/g-drive/adsense/auto-ads-plugin.html

Google Tag Manager

GoogleタグマネージャーでAmazonアソシエイトのクリック数を計測する方法

How to Install and Setup Google Tag Manager in WordPress

header.phpへ追記

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXXXXX');</script>
<!-- End Google Tag Manager -->

body tag直後に追記

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

 

カエレバ カスタムCSS
/*ヨメレバ・カエレバ(レスポンシブ)*/
.booklink-box, .kaerebalink-box {
 padding: 22px 25px 22px 25px;
 width: 100%;
 margin: px;
 border: 1px solid #dfdfdf;
 box-sizing: border-box;
 text-align: center;
}
.booklink-image, .kaerebalink-image {
 width: 100%;
 margin: 0 0 0px 0;
}
.booklink-image img, .kaerebalink-image img {}
.booklink-info, .kaerebalink-info {
 line-height: 125%;
 width: 100%;
}
.booklink-name, .kaerebalink-name {
 margin: 0 0 0px 0;
}
.booklink-name a, .kaerebalink-name a {
 color: #0066cc;
 text-decoration: underline;
}
.booklink-name > a, .kaerebalink-name > a {
 font-size: 16px;
}
.booklink-name a:hover, .kaerebalink-name a:hover {
 color: #FF9900;
}
.booklink-powered-date, .kaerebalink-powered-date {
 font-size: 8px;
}
.booklink-detail, .kaerebalink-detail {
 color: #333333;
 font-size: 12px;
 margin: 0 0 10px 0;
}
.booklink-link2, .kaerebalink-link1 {}
.booklink-link2 a, .kaerebalink-link1 a {
 width: 100%;
 display: block;
 margin: 0px auto -12px;
 padding: 10px;
 text-decoration: none;
 font-size: 14px;
 font-weight: bold;
 box-shadow: 1px 1px 1px #dcdcdc;
}
.booklink-link2 a:hover, .kaerebalink-link1 a:hover {
 opacity: 0.6;
}

@media screen and (min-width: 800px) {

.booklink-box, .kaerebalink-box {
 text-align: left;
 display: table;
}
.booklink-image, .kaerebalink-image {
 vertical-align: top;
 box-sizing: border-box;
 display: table-cell;
 width: 111px;
 text-align: center;
 margin: 0;
}
.booklink-image img, .kaerebalink-image img {
 max-width: 100%
}
.booklink-info, .kaerebalink-info {
 line-height: 125%;
 vertical-align: top;
 box-sizing: border-box;
 display: table-cell;
 padding-left: 25px;
 width: auto;
}
.booklink-name, .kaerebalink-name {
 margin: 0 0 0px 0;
}
.booklink-name > a, .kaerebalink-name > a {
 font-size: 16px;
}
.booklink-powered-date, .kaerebalink-powered-date {
 margin: 6px 0 0 0;
}
.booklink-detail, .kaerebalink-detail {
 margin: 0 0 14px 0;
}
.booklink-link2 a, .kaerebalink-link1 a {
 width: auto;
 text-align: center;
 margin: none;
}
.booklink-link2 > div, .kaerebalink-link1 > div {
 width: 33.33%;
 padding: 0;
 box-sizing: border-box;
 float: left;
}
}

.shoplinkamazon a {
 color: #ffffff;
 background: #333333;
 border: 2px solid #333333;
  margin: 5px;
  width: 90px;
	border-radius: 5px;
}

.shoplinkrakuten a {
 color: #ffffff;
 background: #bf0000;
 border: 2px solid #bf0000;
}
.shoplinkkindle a {
 color: #ffffff;
 background: #0074c1;
 border: 2px solid #0074c1;
}

 

サービス連携
はてなブログとの連携:functions.phpへリンク追記

WordPressで投稿すると自動ではてなブログの下書きに同期されるようにしました。

WordPressとはてなブログを連携させるのでR

function send_hatena($post_id) {
  $post = get_post($post_id);
 
  $headers = array( 'Content-Type: text/html; charset=UTF-8' );
 
  $to = '                 @blog.hatena.ne.jp';
  $subject = '$post->post_title';
 
  $search = array('<h7','/h7>
','<h6','/h6>','<h5','/h5>','<h4','/h4>','<h3','/h3>','<h2','/h2>','<h1','/h1>','/p>
');
  $replace = array('<h9','/h9>','<h8','/h8>','<h7','/h7>','<h6','/h6>','<h5','/h5>','<h4','/h4>','<h3','/h3>','/p>');
 
  $body  = str_replace($search,$replace,nl2br($post->post_content));
  wp_mail( $to, $subject, $body, $headers );
  remove_filter( 'wp_mail_content_type', 'text/html' );
 
  return;
}
add_action( 'publish_post', 'send_hatena', 1 ,6);

SSL https

サイトのhttps化が終わった後は、GoogleアナリティクスとSearch Consoleの設定をちゃんと変更しよう

WEBカテゴリの最新記事