Skip to content

Instantly share code, notes, and snippets.

@gatespace
gatespace / datecontent-shortcode.php
Created May 28, 2012 06:34
WordPressの本文の内容を指定日時によって表示するショートコード
<?php
/**
* @package datecontent_shortcode
* @version 1.0
*/
/*
Plugin Name: 指定日時によって内容を表示するショートコード
Plugin URI: https://gist.github.com/2817701
Description: WordPressの本文の内容を指定日時によって表示するショートコード。使い方は [datecontent opendate="YmdHi" closedate="YmdHi"]指定日時で表示する内容[/datecontent] です。opendate で表示の開始日時、closedate で表示の終了日時をYmdHiの形式で指定します。
Author: gatespace
@gatespace
gatespace / author_rewrite_empty.php
Last active June 15, 2016 03:46
WordPressで投稿者アーカイブを作らないフィルター via. http://gatespace.jp/2012/05/16/author-archive-rewrite-rule/
<?php
/**
* 投稿者アーカイブを作らないフィルター
* テーマのfunctions.phpに記述後、設定→パーマリンク設定を更新(flush_rules() を実行)すること。
*/
add_filter( 'author_rewrite_rules', '__return_empty_array' );
@gatespace
gatespace / littleflag-functions.php
Created June 8, 2012 00:35
WordPressのいろいろなスニペットを詰め込んでおくプラグイン
<?php
/*
Plugin Name: littleflag.com Hacks
Plugin URI:
Description: いろいろなスニペット
Version: 0.1
Author: littleflag.com
Author URI: http://www.littleflag.com/
このプラグインと同じ階層に /lf-func/ というディレクトリを作り、
@gatespace
gatespace / is_new_post.php
Created June 8, 2012 00:56
WordPressで表示する記事が新着かどうかを判別するコード
<?php
/**
* post_classの出力するclassに、新着であれば、new-post、更新であれば、modified-postを追加する。
* 条件分岐タグ : 新着かどうか is_new_post() 、更新かどうか is_modified_post
* ループ外で使う場合 : is_new_post( $new_post->post_date )
* 設定した期間を異なる期間で判定(3日以内の更新かどうかを判定) :
* is_modified_post( $new_post->post_modified, 3 )
*
* 参照 : http://www.warna.info/archives/2034/
*
@gatespace
gatespace / my_content_feed.php
Created June 8, 2012 04:17
WordPressのフィードの本文を変更
<?php
/**
* 登録ユーザー限定コンテンツがある場合のフィードの本文
*/
function my_content_feed( $content ) {
$content = "※会員専用情報です。";
return $content;
}
add_filter('the_content_feed', 'my_content_feed', 10, 2);
add_filter('the_excerpt_rss', 'my_content_feed', 10, 2);
@gatespace
gatespace / htaccess.txt
Created June 29, 2012 04:51
画像のリファラを取得して直接アクセスした場合は403にする.htaccess
# 出典 http://ja.forums.wordpress.org/topic/8980
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
</IfModule>
@gatespace
gatespace / post_type_research_add_meta_box.php
Created September 24, 2012 01:47
カスタム投稿タイプAとBを紐づけるメタボックス
<?php
/*
* カスタム投稿タイプ「research」の投稿画面に
* カスタム投稿タイプ「teacher」の投稿一覧のメタボックスを追加する(チェックボックス編)
* teacherの投稿IDをresearchのカスタムフィールド「teacher_ID」に配列で保存
*/
add_action( 'add_meta_boxes', 'add_teacher_list_box' );
function add_teacher_list_box() {
add_meta_box('teacher_list', '教員一覧', 'teacher_list_custom_box', 'research', 'side', 'low');
@gatespace
gatespace / register_post_type.php
Created October 4, 2012 06:52
カスタム投稿タイプと専用ユーザー権限
<?php
/*
Plugin Name: カスタム投稿タイプと専用ユーザー権限
Plugin URI:
Description: カスタム投稿タイプ「report」とカスタムタクソノミー「reportcat」を作成し、専用の権限グループ「レポート投稿者(report_author)」を作成します。
Author: Your Name
Version: 1.0
Author URI:
*/
@gatespace
gatespace / tiny_mce_add_buttons.php
Last active October 11, 2015 17:07
WordPressのTinyMCEにボタンを追加
<?php
/**
* TinyMCEにボタンを追加
* 参照: http://www.411.co.jp/article/2010/12/wordpress-vediter/
*/
function lf_mce_buttons($buttons){
array_push($buttons, "wp_page");
return $buttons;
}
@gatespace
gatespace / jp_date_archive_wp_title.php
Created October 15, 2012 08:27
WordPress日付別アーカイブタイトルを修正
<?php
/**
* 日付別アーカイブタイトルを修正
* http://memo.dogmap.jp/2012/04/16/wordpress-fix-date-archive-title/
*/
function jp_date_archive_wp_title( $title ) {
if ( is_date() ) {
$title = '';
if ( $y = intval(get_query_var('year')) )