Skip to content

Instantly share code, notes, and snippets.

@gatespace
gatespace / events.html
Created November 8, 2017 11:44
Jekyll でCSVファイルを読み込んでHTMLとして表示 ref: http://qiita.com/gatespace/items/2ba2268f2cb4880eb66c
{% for event in site.data.events %}
<div class="previous-event">
{% if event.name != 'blank' %}
<a href="{{event.url}}" target="_blank">
{% if event.cover %}<img src="{{ site.baseurl }}/assets/images/site-cover/{{event.cover}}" alt="{{event.name}}"><br>{% endif %}
{{event.name}}
{% if event.date %} at {{event.date}}{% endif %}
</a>
{% endif %}
</div>
@gatespace
gatespace / movie.js
Created November 6, 2017 11:34
サイト内の動画をGoogleアナリティクスで計測したい(WordPressの場合のおまけ付き) ref: http://qiita.com/gatespace/items/dee511d0155336e49dc8
// video ga
var video = $('video');
var video_url = '';
if( video.length > 0 ){
var isPlay = false;
video.on('play playing',function(){
if( isPlay === false ) {
video_url = $(this).attr( 'src' );
// Googleアナリティクス analytics.js の場合
if ( typeof ga === 'function' ) {
@gatespace
gatespace / file0.php
Last active February 14, 2018 04:26
WordPress 特定の投稿だけAMPにしたい ref: https://qiita.com/gatespace/items/2b305b12845b952c6943
<?php
add_filter( 'amp_skip_post', 'my_amp_skip_post' 10, 3 );
function my_amp_skip_post( $flag, $post_id, $post ) {
$flag = true;
$checked = get_post_meta( $post_id, '_my_amp_post_control', true ); // カスタムフィールドの値取得
if ( $checked == 1 ) {
$flag = false;
}
return $flag;
@gatespace
gatespace / file0.php
Last active July 18, 2017 04:32
WordPress カスタム分類(タクソノミー)にデフォルトでチェックをいれたい ref: http://qiita.com/gatespace/items/ca6fedb03b10ff8b746c
<?php
// カスタム分類(タクソノミー)の book の スラッグ blue がチェックされてるかどうか
add_action( 'admin_head-post-new.php', 'book_term_post_edit_required' ); // 新規投稿画面でフック
add_action( 'admin_head-post.php', 'book_term_post_edit_required' ); // 投稿編集画面でフック
function book_term_post_edit_required() {
// book タクソノミーの blue タームのIDを取得
$book_term = get_term_by( 'slug', 'blue', 'book' );
$book_term_id = $book_term->term_id;
// ここでIDの有無をちゃんとチェックした方がいいのだけどね。
?>
@gatespace
gatespace / file0.php
Last active July 6, 2017 01:22
WordPress ショートコードの作成とエディタへのボタン追加 ref: http://qiita.com/gatespace/items/bf46f5da04bd0493a5d3
// Add Shortcode [myshortcode][/myshortcode]
function my_shortcode_func( $atts , $content = null ) {
return '<div>' . $content . '</div>';
}
add_shortcode( 'myshortcode', 'my_shortcode_func' );
@gatespace
gatespace / my_localizable_post_types1.php
Last active June 8, 2017 06:03
WordPress Bogo をカスタム投稿タイプでも使う ref: http://qiita.com/gatespace/items/75e70f5ae162c2962dcc
<?php
/**
* Support custom post type with bogo.
*
* @param array $localizable Supported post types.
* @return array
*/
function my_localizable_post_types( $localizable ) {
$localizable[] = 'custom_post_type_name';
return $localizable;
@gatespace
gatespace / get_the_post_thumbnail.php
Last active June 12, 2017 10:27
WordPress imgタグに独自のクラスや属性を追加する ref: http://qiita.com/gatespace/items/266142ce1dc84cb6f31c
<?php
get_the_post_thumbnail(
$post,
$size,
array(
'class' => 'lazy',
'data-original' => 'img/example.jpg'
)
);
@gatespace
gatespace / .gitignode
Last active August 4, 2017 14:02
Travis CI でビルドが成功した場合だけ Netlify にデプロイ ref: http://qiita.com/gatespace/items/146b75de89df6abc5ddb
id_rsa
id_rsa.pub
@gatespace
gatespace / file0.js
Created May 10, 2017 09:23
とにかく右クリックを禁止したい(コンテキストメニューを出さない) ref: http://qiita.com/gatespace/items/1ac927164533b29f1dcc
<script>
jQuery(function($){
$(document).on('contextmenu',function(){ return false; });
});
</script>
@gatespace
gatespace / file0.php
Last active March 8, 2017 06:02
WordPress カスタム投稿タイプのアーカイブをカスタムメニューで追加してCSSクラスもいい感じに付与 ref: http://qiita.com/gatespace/items/163e42019c40d7f1b01a
<?php
function my_special_nav_class( $classes, $item ) {
// カスタム投稿タイプ special の投稿が表示されてる時カスタム投稿タイプアーカイブがメニューにあればCSSクラスを追加。
if ( is_singular( 'special' ) && $item->type === 'post_type_archive' && $item->object === 'special' ) {
if ( ! in_array( 'current-post-ancestor', $classes ) ) {
$classes[] = 'current-post-ancestor';
}
}
return $classes;
}