Skip to content

Instantly share code, notes, and snippets.

@momo-soune
momo-soune / custom_thumnail
Last active April 22, 2019 23:50
WordPress テーマ【JIN】用の画像のカスタマイズ
function custom_thumnail($html, $post_id, $post_image_id,$size,$attr){
if(has_post_thumbnail()){
if(is_single() && ! wp_is_mobile()){ //singleページ&PCアイキャッチ用
$eyecatch = get_the_post_thumbnail( 'large_size' );
$html = '<img src="';
$html .= 'ローディング画像URL';
$html .= '" data-echo="';
$html .= $eyecatch;
$html .= '" alt="';
$html .= get_post_meta( $post_image_id, '_wp_attachment_image_alt', true );
@momo-soune
momo-soune / functions.php
Last active March 14, 2019 04:42
WordPress JIN テーマ タイトルタグの修正
//カスタムカテゴリーのタイトル取得
function cps_category_title($display = true){
global $post;
$t_id = get_category( intval( get_query_var('cat') ) )->term_id;
$cat_class = get_category($t_id);
$cat_option = get_option($t_id);
if( isset($cat_option['cps_meta_title']) && $cat_option['cps_meta_title'] !== '' ){
$category_title = $cat_option['cps_meta_title'];
@momo-soune
momo-soune / index.php
Created December 4, 2018 00:58
Gutenbergでブロックカテゴリーを作成するソース
function jin_blocks_categories( $categories, $post ) {
return array_merge(
$categories,
array(
array(
'slug' => 'jin-blocks',
'title' => __( 'Jin Blocks', 'jin-blocks' ),
'icon' => 'wordpress',
),
)
@momo-soune
momo-soune / related_tag.php
Created August 12, 2018 13:11
記事にタグ付けられた関連記事をリスト化します。
@momo-soune
momo-soune / Simple_GA_Ranking_Widget.php
Last active July 30, 2018 14:21
Simple_GA_Rankingでカテゴリー別にランキングを表示するカスタマイズ
class Simple_GA_Ranking_Widget extends WP_Widget {
public function __construct() {
$widget_ops = array('classname' => 'widget-popular', 'description' => __('Simple Ga Rankingウィジェットです'));
$control_ops = array('width' => 400, 'height' => 350);
parent::__construct('Simple_GA_Ranking_Widget', __('Simple GA Rankingのウィジェット'), $widget_ops, $control_ops);
}
public function widget( $args, $instance ) {
extract($args);
@momo-soune
momo-soune / amazonjs.php
Created July 27, 2018 09:51
AmazonJSの商品名に付随する部分を削除するカスタマイズーL240行目付近の$amazonVars = array(の上に追記する
foreach ($items as &$Retitle) {
$Retitle["Title"] = preg_replace('/\s\([\W-\w]*\)$/','',$Retitle["Title"]);
}
unset($Retitle);
@momo-soune
momo-soune / amazonjs.js
Last active July 30, 2018 02:44
amazonjs.jsをWordPress有料テーマ【JIN】に合うようにカスタマイズする方法
(function ($) {
if (!$) return;
var ua = navigator.userAgent,
isIE = ua.match(/msie/i),
isIE6 = isIE && ua.match(/msie 6\./i),
location = window.location,
isHttpsScheme = location && location.protocol && location.protocol == 'https:';
$.extend({
amazonjs:{
imageAttributes: ['SmallImage', 'MediumImage', 'LargeImage'],
@momo-soune
momo-soune / header-nosearch.php
Created July 26, 2018 13:54
WordPressでページングページをGoogle検索結果に表示しない方法です。
<?php
if(($paged >= 2 || $page >= 2 ) && ! is_404()){
echo "<meta name="robots content="noindex >";
} ?>
@momo-soune
momo-soune / header_custom.php
Created July 26, 2018 13:52
Search Console(サーチコンソール)のメタ情報の重複を回避するカスタマイズです。
<?php global $page, $paged;if( is_home() || is_front_page() ): ?>
<?php $mydesc = get_bloginfo('description') ?>
<?php if( ! empty( $mydesc ) ): ?>
<title><?php bloginfo('name'); ?>|<?php bloginfo('description'); ?></title>
<?php else: ?>
<title><?php bloginfo('name'); ?></title>
<?php endif; ?>
<?php elseif(is_page()): ?>
<title><?php wp_title('','right'); ?>|<?php bloginfo('name'); ?></title>
<?php elseif(($paged >= 2 || $page >= 2 ) && ! is_404()): ?>