Skip to content

Instantly share code, notes, and snippets.

View mhige's full-sized avatar

minaminohige mhige

View GitHub Profile
@mhige
mhige / function.php
Created December 10, 2019 04:01
AMPを表示したいページとしたくないページを切り分ける例(コメントなし)
<?php
function amp_link_tag(){
$content = apply_filters('the_content', get_post_field('post_content', get_the_ID()));
$no_amp_a8ad = preg_match('/<a.*?href="https:\/\/px\.a8\.net/is', $content);
if(is_singular('post') && is_mobile() && !$no_amp_a8ad){
$amp_param = '?amp=1';
echo '<link rel="amphtml" href="'.esc_url(get_permalink()).$amp_param.'">'."\n";
}
}
add_action('wp_head','amp_link_tag');
@mhige
mhige / function.php
Created December 10, 2019 03:01
AMPを表示したいページとしたくないページを切り分ける例
<?php
// ヘッドタグにampのURLを表示する関数
function amp_link_tag(){
// 例えばA8.netのアフィリエイトがあるページはAMP表示しない場合
// 記事の投稿情報をとってくる
$content = apply_filters('the_content', get_post_field('post_content', get_the_ID()));
// preg_matchで$content内のA8のURLをマッチングさせる
$no_amp_a8ad = preg_match('/<a.*?href="https:\/\/px\.a8\.net/is', $content);
// ここに複数条件を入れる
// 記事ページだけ表示する
@mhige
mhige / index.html
Created December 10, 2019 02:34
AMPページをクロールして欲しい場合の記載例
<!DOCTYPE html>
<html lang="ja">
<head>
<!-- AMPページのURLを記載したリンクタグ例 -->
<link rel="amphtml" href="https://example.com/post/?amp=1">
</head>
<body>
</body>
</html>
@mhige
mhige / is_amp-example.php
Last active December 10, 2019 02:26
is_amp関数の使い方例
<?php
if(is_amp()) {
// こちらがAMPがONのとき(パラメータに?amp=1がついているとき)
} else {
// こちらがAMPがOFFのとき(パラメータがない、もしくは?amp=1じゃないとき)
}
?>
@mhige
mhige / function.php
Created December 10, 2019 02:18
パラメータでampにするかどうか決めるis_amp関数
<?php
// AMPページの判断
function is_amp() {
if(isset($_GET['amp']) && $_GET['amp'] == 1){
return true;
} else {
return false;
}
}
?>
@mhige
mhige / function.php
Last active December 2, 2019 04:59
Wordpress更新通知ライブラリを走らせるPHP(plugin-update-checker)
<?php
// テーマの更新通知確認
require 'plugin-update-checker-4.8.1/plugin-update-checker.php';// ←バージョンは自分のダウンロードしたやつに合わせてください
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
// ↓jsonファイルを置いた場所
'https://example.com/theme-update.json',
__FILE__,
'minamino' // テーマの名前
);
?>
@mhige
mhige / style.css
Created December 2, 2019 03:09
Wordpressの更新機能を追加する時のstyle.cssの記述例
@charset "UTF-8";
/*---------------------------------------------------------
Theme Name: minamino
Theme URI: https://example.com/download/minamino/
Description: Wordpressテーマの説明
Author: 作者名
Author URI: 著者のサイトURL
License:著作権ライセンス
License URI:ライセンスのURL
Tags:検索向けのタグ
@mhige
mhige / theme-update.json
Created December 2, 2019 03:01
Wordpressのテーマ更新機能実装、更新確認用のjsonファイル記載例
{
"version": "1.1.3",
"details_url": "https://example.com/",
"download_url": "https://example.com/download/minamino.zip"
}
@mhige
mhige / swiper-slide.html
Created September 25, 2018 09:13
SwiperのHTML部分
<!-- HTML構造とclass名を守る-->
<div class="swiper-container">
<div class="swiper-wrapper">
<!-- ここに表示したいスライド(これは3枚分) -->
<div class="swiper-slide">スライド 1</div>
<div class="swiper-slide">スライド 2</div>
<div class="swiper-slide">スライド 3</div>
</div>
@mhige
mhige / custom.js
Created September 25, 2018 09:04
Swiperを動かす
//swiper.js
//jQuery使ってます..
$(document).ready(function () {
// swiperをイニシャライズ
var mySwiper = new Swiper ('.swiper-container', {
// オプションのパラメーターを指定
direction: 'horizontal',
effect: "flip",
loop: true,
spaceBetween: 30,