Skip to content

Instantly share code, notes, and snippets.

@yhira
yhira / rakuten.php
Created April 25, 2019 11:02
ビジュアルエディタのショートコードプルダウンにアイテムを追加する
<?php //商品追加ショートコード
$before = '[rakuten search="商品名" kw="商品名" title="商品名"]';
$after = '';
?>
shortcodes[18] = new Array();
shortcodes[18].title = '<?php echo __( '楽天商品リンク(独自追加)', THEME_NAME ); ?>';
shortcodes[18].tag = '<?php echo $before.$msg.$after; ?>';
shortcodes[18].before = '<?php echo $before; ?>';
shortcodes[18].after = '<?php echo $after; ?>';
@yhira
yhira / get_rating_star_tag.php
Created April 15, 2019 10:04
レーティングスタータグの取得
function get_rating_star_tag($rate, $max = 5, $number = false){
$rate = floatval($rate);
$max = intval($max);
//数字じゃない場合
if (!is_numeric($rate) || !is_numeric($max)) {
return $rate;
}
//レーティングが100より多い場合は多すぎるので処理しない
if ($rate > 100 && $max > 100) {
return $rate;
@yhira
yhira / smartnews.php
Created March 23, 2019 01:42
SmartNewsフィード出力テンプレート
<?php
/**
* RSS2 Feed Template for displaying RSS2 Posts feed.
*
* @package SmartNews
*/
/**
* 寝ログ
* @author: yhira
@yhira
yhira / cocoon_exclude_script_movement_from_content.php
Last active February 23, 2019 14:01
コンテンツから移動しないスクリプトファイル条件を追記する
//本文中から移動しないスクリプトコード条件を追記する
add_filter('cocoon_exclude_script_movement_from_content', function($is_exclude, $script){
return $is_exclude || includes_string($script, 'tradingview_embed_options');
}, 10, 2);
@yhira
yhira / site-title-br.js
Created November 23, 2018 10:46
Cocoonのサイトタイトルを改行するJavaScript(jQuery)
(function($){
var siteTitle = $('#header .site-name-text').text();
siteTitle = siteTitle.replace("Cocoonデモサイト", "Cocoon<br>デモサイト");
$('#header .site-name-text').html(siteTitle);
})(jQuery);
@yhira
yhira / appeal-wrap.php
Created November 19, 2018 14:20
アピールエリアに画像リンクのみを表示する
<?php //アピールエリア
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/ ?>
<?php //アピールエリアを表示するか
if (is_appeal_area_visible() && !is_amp()): ?>
<a href="<?php echo get_appeal_area_button_url(); ?>" class="appeal-wrap">
@yhira
yhira / toc-2.php
Created October 28, 2018 10:07
Cocoonの目次部分を2カラムにする
add_filter( 'get_toc_tag', get_toc_tag_custom, 10, 3 );
if ( !function_exists( 'get_toc_tag_custom' ) ):
function get_toc_tag_custom($html, &$harray, $is_widget){
if ($is_widget) {
return $html;
}
ob_start();?>
<div class="column-wrap column-2">
<div class="column-left">
<?php echo $html; ?>
@yhira
yhira / ResponseGroup=temAttributes,Images,Offers.xml
Created October 8, 2018 13:04
Amazon APIのレスポンスメモ
<?xml version="1.0" ?>
<ItemLookupResponse
xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<OperationRequest>
<RequestId>187476be-951c-4d4f-a2b0-933d0ecb6220</RequestId>
<Arguments>
<Argument Name="AWSAccessKeyId" Value="XXXXXXXXXXXXXXXXXXXXXX"></Argument>
<Argument Name="AssociateTag" Value="XXXXXXX-22"></Argument>
<Argument Name="ItemId" Value="B00BJRU9IG"></Argument>
<Argument Name="Operation" Value="ItemLookup"></Argument>
@yhira
yhira / title_parts_custom.php
Last active September 10, 2018 11:46
Cocoonのタイトル変更関数
function title_parts_custom( $title ){
$site_name = trim( get_bloginfo('name') );
$title['tagline'] = '';
if(is_front_page()){ //フロントページ
//自由形式タイトルの場合
if (is_free_front_page_title()) {
$title['title'] = esc_html( get_free_front_page_title() );
} else {//自由形式でないとき
$title['title'] = $site_name;
@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,'');