Skip to content

Instantly share code, notes, and snippets.

@gatespace
gatespace / add_column.php
Last active February 9, 2017 05:12
WordPress 管理画面の投稿一覧にカラムを追加してカスタムフィールドの値を出す ref: http://qiita.com/gatespace/items/199c9995e47d668e0fb0
<?php
// カスタム投稿タイプ book の投稿一覧で作成者名を削除し、本の著者名を追加
function add_book_columns( $columns ) {
// 削除(作成者名)
unset( $columns['author'] );
// 追加
$new_columns = array(
'book_author' => __( 'Book Author', 'my_theme' ),
);
@gatespace
gatespace / add_term_dropdown.php
Last active February 8, 2017 08:49
WordPress 管理画面でカスタム投稿タイプの投稿一覧にカスタムタクソノミーの絞込をつける ref: http://qiita.com/gatespace/items/39a030c0303f6e82d35d
<?php
add_action( 'restrict_manage_posts', 'add_term_dropdown', 10, 2 );
function add_term_dropdown( $post_type ) {
if ( 'session' == $post_type ) { // カスタム投稿タイプ 'session' の場合
$term_slug = get_query_var( 'session_track' );
wp_dropdown_categories( array(
'show_option_all' => __( 'All Tracks', 'my_theme' ),
'selected' => $term_slug, // 絞り込んだあとそのタームが選択されている状態を維持
'name' => 'session_track', // select の name 属性
'taxonomy' => 'session_track', // カスタムタクソノミーのスラッグ
@gatespace
gatespace / file1.txt
Last active February 8, 2017 09:33
WordPress Transients API を使うときの覚書 ref: http://qiita.com/gatespace/items/90fad367f9ad0626e720
# Set transient.
$ wp transient set sample_key "test data" 3600
Success: Transient added.
# Get transient.
$ wp transient get sample_key
test data
# Delete transient.
@gatespace
gatespace / file0.php
Last active December 26, 2016 10:24
WordPress カスタム投稿タイプに既存のカテゴリー(タグ)を追加しつつ、カテゴリー(タグ)アーカイブにカスタム投稿タイプの投稿を含める ref: http://qiita.com/gatespace/items/7b657ff28c1ee4e948ed
// Register Custom Post Type
function add_custom_post_type_book() {
$labels = array(
'name' => _x( 'Books', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Book', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Books', 'text_domain' ),
'name_admin_bar' => __( 'Book', 'text_domain' ),
'archives' => __( 'Item Archives', 'text_domain' ),
'attributes' => __( 'Item Attributes', 'text_domain' ),
@gatespace
gatespace / file2.html
Last active December 8, 2016 05:53
WordPress テーマカスタマイザーで動画を追加して出力(ver 4.7以降の場合) ref: http://qiita.com/gatespace/items/760533f0c90095cc6571
<button type="button" id="wp-custom-header-video-button" class="wp-custom-header-video-button wp-custom-header-video-play">Pause</button>
@gatespace
gatespace / add_comment_count.php
Last active February 2, 2018 10:43
[ざっくり翻訳] WordPress AMP プラグイン カスタマイズなどの説明 ref: https://qiita.com/gatespace/items/8087f1e19ffb81aeab15
add_filter( 'amp_post_article_footer_meta', 'xyz_amp_add_comment_count_meta' );
function xyz_amp_add_comment_count_meta( $meta_parts ) {
$meta_parts[] = 'xyz-meta-comment-count';
return $meta_parts;
}
add_filter( 'amp_post_template_file', 'xyz_amp_set_comment_count_meta_path', 10, 3 );
function xyz_amp_set_comment_count_meta_path( $file, $type, $post ) {
@gatespace
gatespace / custom_excerpt_length.php
Last active January 24, 2019 06:54
テキストを指定した文字数または行数でカットする ref: https://qiita.com/gatespace/items/08c3457cd7fcc232f131
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
@gatespace
gatespace / add-user-contactmethods.php
Last active February 10, 2017 01:51
WordPress ユーザー情報の拡張とアバター画像とその表示 ref: http://qiita.com/gatespace/items/9a586da6b724107727ad
<?php
// Register User Contact Methods
function custom_user_contact_methods( $user_contact_method ) {
$user_contact_method['facebook'] = __( 'Facebook Username', 'text_domain' );
$user_contact_method['twitter'] = __( 'Twitter Username', 'text_domain' );
$user_contact_method['gplus'] = __( 'Google Plus', 'text_domain' );
$user_contact_method['skype'] = __( 'Skype Username', 'text_domain' );
return $user_contact_method;
@gatespace
gatespace / entry-content.scss
Last active September 1, 2016 08:50
WordPress 投稿(固定ページ)本文欄で使えるタグで作っておいたほうがいいスタイル ref: http://qiita.com/gatespace/items/cdff541981f7cffddfab
.page-content,
.entry-content,
.mceContentBody {
// styles in entry-content.
/* Headings */
h1 {
}
h2 {
}
h3 {
$width__border: 6px;
$color__border: red;
h1 {
font-size: 18px;
border-left-style: solid;
border-left-width: $width__border;
border-left-color: $color__border;
position: relative;
padding-left: 10px;
&:before,