Skip to content

Instantly share code, notes, and snippets.

View ShinichiNishikawa's full-sized avatar
🏠
Working from home

Shinichi Nishikawa ShinichiNishikawa

🏠
Working from home
View GitHub Profile
@ShinichiNishikawa
ShinichiNishikawa / newreview
Last active June 26, 2016 14:08
Creating a whole new Theme Review environmet in 1 minute using wp-cli
wp db reset --yes
wp core install --url=http://theme-review.loc --title="This is a really long long title to check if this theme design doesn't break with the long site title" --admin_user=admin --admin_password=admin [email protected]
wp core update
wp plugin install theme-check debug-bar log-deprecated-notices monster-widget wordpress-importer show-current-template customizer-theme-resizer --activate
wp plugin install wordpress-beta-tester debogger jetpack
wp plugin update --all
wp option update blogdescription "I'm in the theme review process and this is a very very long tagline to see if this long tagline text string in WordPress doesn't break the design of the theme header and else."
wp option update posts_per_page 5
wp option update thread_comments 1
wp option update thread_comments_depth 3
@ShinichiNishikawa
ShinichiNishikawa / add_body_class_locale.php
Last active August 29, 2015 14:02
Add locale to body_class
// add locale such as locale_ja, locale_en_US to body class
add_filter( 'body_class', 'add_body_class_locale' );
function add_body_class_locale( $classes ) {
$classes[] = 'locale_' . sanitize_html_class( get_bloginfo('language') );
return $classes;
}
@ShinichiNishikawa
ShinichiNishikawa / gist:11371541
Last active August 29, 2015 14:00 — forked from wokamoto/gist:11365599
おかもとさんより
<?php
add_filter( 'the_content', 'my_pre_shortcode', 7 );
function my_pre_shortcode( $content ) {
global $shortcode_tags;
$shortcode_tags_org = $shortcode_tags;
remove_all_shortcodes();
add_shortcode( 'code', 'code_shortcode_handler' );
$content = do_shortcode( $content );
<?php
/**
* @package content_mayuge_systems
* @version 0.2
*/
/*
Plugin Name: Content Mayuge Systems
Plugin URI: http://wordpress.org/extend/plugins/hello-dolly/
Description: 本文中に句点「。」があると「( ・ิω・)╯ิ」がくっつきます。
Author: gatespace
<?php
// エディタの下にテキストエリアを追加
add_action( 'edit_form_after_editor', 'nskw_postMetaAfterEditor' );
function nskw_postMetaAfterEditor() {
global $post;
$metaKey = 'afterEditor';
if ( empty ( $post ) || 'post' !== get_post_type( $GLOBALS['post'] ) ) {
return;
}
if ( ! $content = get_post_meta( $post->ID, $metaKey, TRUE ) ) {
@ShinichiNishikawa
ShinichiNishikawa / functions.php
Last active December 16, 2015 16:40
テーマ作るときのデフォルトのfunctions.php
<?php
// アイキャッチ
add_theme_support('post-thumbnails');
// set_post_thumbnail_size(443, 171, true);
// その他の画像サイズ
//add_image_size( 'sizename', 100, 100, true );
// jQuery の差し替えとその他のJSの登録
@ShinichiNishikawa
ShinichiNishikawa / postMetaAfterTitle.php
Last active December 15, 2015 08:49
WordPressの管理画面の投稿タイトルの下に、ポストメタの入力欄を追加する
// タイトル下にタイトル2を追加
add_action( 'edit_form_after_title', 'nskw_postMetaAfterTitle' );
function nskw_postMetaAfterTitle() {
global $post;
$metaKey = 'title2';
if ( empty ( $post ) || 'post' !== get_post_type( $GLOBALS['post'] ) ) {
return;
}
if ( ! $content = get_post_meta( $post->ID, $metaKey, TRUE ) ) {
$content = '';
<?php
// タクソノミ取得
$catargs = array(
'taxonomy' => 'specialcat'
);
$catlists = get_categories( $catargs );
foreach($catlists as $cat) : // 取得したカテゴリの配列でループを回す
/*
// タクソノミひとつひとつのオブジェクトの中身を見る
if ( is_user_logged_in() ) {
@ShinichiNishikawa
ShinichiNishikawa / gist:4144842
Created November 25, 2012 19:15
管理画面の投稿一覧に、カスタムタクソノミの列を追加する
// 投稿一覧で表示する項目を操作する
function manage_posts_columns($columns) {
unset($columns['tags']);
unset($columns['comments']);
global $post;
if ( $post->post_type == 'post' ) { // ポストタイプが投稿の時だけ
$date_escape = $columns['date']; // いったん避難
unset($columns['date']); // 消す
$columns['district'] = '地区';
$columns['date'] = $date_escape; // ここで戻すと日付が最後になる
@ShinichiNishikawa
ShinichiNishikawa / gist:4139916
Created November 24, 2012 14:36
こっちでよかった。カテゴリ/タクソノミをGETで受け取った時のバリデーション。Validate GET values against cattegories / taxonomies the site has.
<?php
// category の場合
$what = get_term_by( 'name', $_GET['what'], 'category', 'ARRAY_A' );
// district というタクソノミの場合
$where = get_term_by( 'name', $_GET['where'], 'district', 'ARRAY_A' );
// https://gist.github.com/4139337 これが長い方