Instantly share code, notes, and snippets.

View CustomDie.php
<?php
/**
* 味気ないwp_dieの出力を変更する
*/
class CustomDie {
public function __cosntruct() {
}
public function enable_custom_die() {
View modal-focus.js
// モーダル開閉時のフォーカス操作(モーダルのルート要素にtabindex=0必要)
$('.uk-modal').on('show', (e) => {
$(e.target).data('lastFocusdElement', window.document.activeElement).focus();
}).on('hide', (e) => {
$(e.target).data('lastFocusdElement').focus();
});
View responsive.scss
@function percentage-vw($num) {
$per: ($num * 100);
@return #{$per}vw;
}
@mixin responsive-width($width, $base: 750px) {
width: percentage($width / $base);
max-width: $width;
}
View wp-remove-all-rest-endpoint.php
add_filter( 'rest_endpoints', function( $endpoints ){
if ( isset( $endpoints['/wp/v2/posts'] ) ) {
unset( $endpoints['/wp/v2'] );
}
if ( isset( $endpoints['/wp/v2/posts'] ) ) {
unset( $endpoints['/wp/v2/posts'] );
}
if ( isset( $endpoints['/wp/v2/posts'] ) ) {
unset( $endpoints['/wp/v2/posts'] );
}
View countdown.js
class Countdown {
constructor() {
this.limit = new Date(META.limitdate);
this.labels = ['days', 'hours', 'minutes', 'seconds'];
this.elements = {};
this.nums = {};
this.onStop = () => {};
this.labels.forEach((label) => {
this.elements[label] = window.document.querySelector(`.countdown > .nums.${label}`);
View wp-admin-columns-manage-sample.php
/**
* カラムの追加と削除
*/
add_filter('manage_cat_story_posts_columns' , function ($columns) {
 //削除
unset( $columns['author'] );
unset( $columns['comments'] );
$new_columns = array(
View custom_header_carousel.php
View gulp.clean.js
var fs = require('fs'),
del = require('del');
gulp.task('clean', function(done) {
var files = fs.readdirSync('dist');
var targets = [];
if(files.length) {
targets.push('dist/*');
View get_category_custom_field.php
/**
* カテゴリー一覧で表示されている記事のカスタムフィールドの値を得る
* @return Array カスタムフィールド値の配列
*/
function get_category_custom_field($cat_id) {
global $wpdb;
$meta_key = 'your_custom_field_key';
$limit = get_option('posts_per_page');
$offset = get_query_var('paged') * $limit;
View duration_time.js
function duration(str) {
var matches = str.match(/PT(\d*)H*(\d+)M*(\d+)S*/i);
var d = (matches[1] && matches[1] + ':'); //hour
d += (matches[1] && matches[2] < 10 ? '0' : '') + (matches[2] && matches[2] + ':'); //min
d += (matches[3] && matches[3] < 10 ? '0' : '') + (matches[3] && matches[3]); //sec
return d;
}