Skip to content

Instantly share code, notes, and snippets.

@yhira
yhira / Amazon商品リンク.js
Created August 30, 2018 09:05
CocoonのAmazon商品リンクショートコード作成ブックマークレット
javascript:(function(){
var host = location.host;
if (host == 'www.amazon.co.jp'){
var titleElems = [
document.getElementById('productTitle'),
document.getElementById('ebooksProductTitle'),
document.getElementById('aiv-content-title'),
document.getElementById('title_feature_div')
];
var title = titleElems.filter(v => {return v!=null;})[0].innerText.trim().replace(/[\[|\]]/g,'');
@yhira
yhira / add_default_site_icon_tag.php
Last active May 31, 2020 13:30
Cocoonのデフォルトサイトアイコンを変更する
//デフォルトのサイトアイコンを変更する
add_filter('add_default_site_icon_tag', function ($tag){
$tag = '<link rel="icon" href="32x32画像のURL" sizes="32x32" />'.PHP_EOL;
$tag .= '<link rel="icon" href="192x192画像のURL" sizes="192x192" />'.PHP_EOL;
$tag .= '<link rel="apple-touch-icon" href="180x180画像のURL" />'.PHP_EOL;
$tag .= '<meta name="msapplication-TileImage" content="270x270画像のURL" />'.PHP_EOL;
return $tag;
});
@yhira
yhira / balloon.php
Created May 27, 2020 11:24
[Cocoon]吹き出しショートコード簡略版
add_shortcode('hukidashi1', 'hukidashi1Func');
function hukidashi1Func( $atts, $content = null ) {
ob_start();
?>
<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-3 sbs-line sbp-l sbis-cb cf block-box">
<div class="speech-person">
<figure class="speech-icon"><img data-src="http://cocoon.local/wp-content/themes/cocoon-master/images/b-man.png" alt="bbb" class="speech-icon-image " src="http://cocoon.local/wp-content/themes/cocoon-master/images/b-man.png" data-loaded="true">
<noscript><img src="http://cocoon.local/wp-content/themes/cocoon-master/images/b-man.png" alt="bbb" class="speech-icon-image" /></noscript>
</figure>
<div class="speech-name">名前</div>
@yhira
yhira / author-box.php
Last active April 24, 2020 11:09
プロフィールボックスのHTML
<div class="author-box border-element no-icon cf">
<figure class="author-thumb"> <img alt="monta" src="https://tukalog.com/wp-content/uploads/2020/03/monta.png" class="avatar avatar-200 photo" width="200" height="200"> </figure>
<div class="author-content">
<div class="author-name"> <a href="https://tukalog.com/profile">monta</a> </div>
<div class="author-description">
<p>hi,
<br> i am a hot spring lover.</p>
</div>
<div class="author-follows"> </div>
</div>
@yhira
yhira / external-blogcard.html
Last active April 15, 2020 10:38
Cocoon外部ブログカードのHTML例
<a href="https://wp-simplicity.com/" title="Simplicity" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank" rel="noopener">
<div class="blogcard external-blogcard eb-left cf">
<div class="blogcard-label external-blogcard-label"><span class="fa"></span></div>
<figure class="blogcard-thumbnail external-blogcard-thumbnail"><img src="https://cocoon.local/wp-content/uploads/cocoon-resources/blog-card-cache/7183f3692da296da4ede1d25e5a91233.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90"></figure>
<div class="blogcard-content external-blogcard-content">
<div class="blogcard-title external-blogcard-title">Simplicity</div>
<div class="blogcard-snippet external-blogcard-snippet">内部SEO施策済みのシンプルな無料Wordpressテーマを公開しています。初心者でも出来る限り分かりやすく使えるように作成しました。</div>
</div>
<div class="blogcard-footer external-blogcard-footer cf">
<div class="blogcard-site external-blogcard-site">
@yhira
yhira / wrap_h2_1st_to_end.php
Last active March 20, 2020 10:59
Cocoonの最初のH2見出しから本文最後までをdiv要素で囲む
//最初のH2見出しから本文最後までをdiv要素で囲む
add_filter('the_content','wrap_h2_1st_to_end', 99999);
function wrap_h2_1st_to_end($the_content) {
//投稿・固定ページの場合
if (is_singular()) {
$h2 = '/<h2/';//H2見出しのパターン
if ( preg_match( $h2, $the_content )) {//H2見出しが本文中にあるかどうか
$the_content = preg_replace($h2, '<div class="hoge"><h2', $the_content.'</div>', 1);//最初のH2を置換
}
}
@yhira
yhira / change_h2_to_but.php
Last active March 9, 2020 11:06
WordPress本文の特定の文字列の見出しを変更する
add_filter('the_content','change_h2_to_but');
function change_h2_to_but( $content ){
return str_replace('<h2>しかし…</h2>','<h2 id="but">しかし…</h2>', $content );
}
@yhira
yhira / OneColumnBlock.js
Created October 17, 2019 18:11
withColorsを使ったサンプル
import classnames from 'classnames';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
RichText,
withColors,
getColorClassName,
@yhira
yhira / use-withColors.js
Last active October 18, 2019 13:18
カラーパレットの設定をHOCで制御(修正版)
import classnames from 'classnames';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
RichText,
withColors,
getColorClassName,
@yhira
yhira / fetch_facebook_count.php
Created April 30, 2019 02:59
Facebookのリアクションカウントを取得する関数
//Facebookのリアクションカウントを取得する
function fetch_facebook_count($url){
//アクセストークンの入力
$access_token = '取得したアクセストークンを入力';
//URLをURLエンコード
$encoded_url = rawurlencode( $url );
//Facebookにリクエストを送る
$request_url = 'https://graph.facebook.com/?id='.$encoded_url.'&fields=engagement&access_token='.$access_token;
$response = wp_remote_get( $request_url );
$res = 0;