Skip to content

Instantly share code, notes, and snippets.

@gatespace
gatespace / disable_feeds.php
Last active November 27, 2017 07:20
WordPressフィードの生成を制御
<?php
/**
* Disable comments feed link
*/
add_filter( 'feed_links_show_comments_feed', function() { return false; } );
/**
* Disable comments feed
*/
function feed_force_404( $obj ) {
@gatespace
gatespace / gist:4108710
Created November 19, 2012 02:52 — forked from tekapo/gist:4108697
最強のテンプレートタグ get_the_khoshino()
<?php
function get_the_khoshino($username == null) {
if (!empty($username)) {
return 'いやいや'.$username.'さんほどでは。';
} else {
return 'やはりですか。なるほどですね。';
}
}
?>
@gatespace
gatespace / view_template_files.php
Last active July 30, 2022 22:04
WordPressのテーマにおいて、テンプレート階層に基づきどのテンプレートファイルが使われているか書き出すコード。 WordPressがデバッグモードのときのみ表示します。 使っているテンプレートファイルはグローバル変数 $template に保存されています。 (ただし、header.php や get_template_part などでインクルードされているファイルを除く) wp_footerにフックする形で関数が実行されますので、テーマのfunctions.phpの適当な箇所に追記してください。
/*
WordPressのテーマにおいて、テンプレート階層に基づきどのテンプレートファイルが使われているか書き出すコード。
ただし、header.php や get_template_part などでインクルードされているファイルを除く。
*/
add_action('wp_footer', 'view_template_files');
if ( !function_exists( 'view_template_files' ) ):
function view_template_files() {
if ( defined('WP_DEBUG') && WP_DEBUG ) {
global $template;
@gatespace
gatespace / show_Cat_Posts_func.php
Last active September 11, 2016 06:36
WordPressで投稿内に指定カテゴリーの記事を表示するショートコード 使い方は投稿の編集画面内で [showcatposts cat="1" show="3"] とする。
/*
使い方は投稿の編集画面内で
[showcatposts cat="1" show="3"]
とする。
*/
function show_Cat_Posts_func($atts) {
global $post;
$output = "";
/*
* ショートコード [showbooks year="2012"] で投稿日を基準に当該年度の記事一覧を出したいという試み
*/
function filter_where( $where = "", $booknend ) {
global $booknend;
$eyear = $booknend + 1;
$where .= " AND post_date >= '{$booknend}-04-01' AND post_date < '{$eyear}-04-01'";
return $where;
}
@gatespace
gatespace / jp_wareki.php
Last active April 4, 2019 08:07
yyyymmddな日付を和暦に変換するPHPスクリプト。年号だけを返すので、月日も返す場合は変更する必要あり。
function jp_wareki( $datenum ) {
$wname = "";
$y = substr( $datenum, 0, 4 );
$m = substr( $datenum, 4, 2 );
$d = substr( $datenum, 6, 2 );
if ( checkdate($m, $d, $y) ) {
if ( $datenum >= 20190501 ) { // 令和
$wname = "R";
$y -= 2018;
@gatespace
gatespace / LINGUAS
Last active December 16, 2015 06:49 — forked from miya0001/Makefile
自分用に改変。
ja
@gatespace
gatespace / default.conf
Last active July 15, 2016 03:00
網元でWordPressの管理画面にアクセス制限(IP or Basic認証)をかける時に /etc/nginx/conf.d/default.conf に追記する内容
server {
# (略)
location ~* /wp-login\.php|/wp-admin/((?!admin-ajax\.php).)*$ {
index index.php index.html index.htm;
# 許可するIPアドレスを記述
allow 192.168.0.1;
deny all;
# Basic認証のメッセージ
@gatespace
gatespace / pc_functions.php
Created June 24, 2013 02:57
[pc-only], [mobile-only] ショートコード。PCとスマートフォンテーマで本文部分を切り分けたい時に。
/*
* [pc-only], [mobile-only] ショートコード(PCテーマ用)
*/
if ( ! function_exists( 'strip_block' ) ):
function strip_block($attr, $content = null) {
return '';
}
endif;
if ( ! function_exists( 'keep_block' ) ):
@gatespace
gatespace / gist:6005221
Last active December 19, 2015 19:19 — forked from hissy/my-adsense.php
自分のブログ用に改造してみた。 ウィジェット部分(常に)、is_singular がtrue なら <!-- more -->部分、本文の最後、かつモバイルでは小さいのが表示されるように。
<?php
/*
Plugin Name: My AdSense
Description: add adsense to my blog
Author: Takuro Hishikawa
Version: 0.1
Author URI: http://notnil-creative.com/
*/
// add adsbygoogle.js to footer