Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
mypacecreator / page-print.php
Last active August 25, 2022 03:07
WordPressで印刷用画面を作る(ブログ用)
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="robots" content="noindex">
<title>印刷用ページのベース(例)</title>
<link rel='stylesheet' id='print-css' href='<?php echo esc_url( get_template_directory_uri() ); ?>/print.css' type='text/css' media='all' />
</head>
<body>
@mypacecreator
mypacecreator / functions.php
Last active December 15, 2021 08:04
カスタムフィールドを使い、投稿ごとにタイトルタグを自由に編集する方法(フィルターフック使用、バージョンチェックあり版)
<?php
//コピペするなら3行目から↓
function mypace_custom_title( $title ){
if( is_singular() ){ //タイトルタグカスタマイズの範囲を条件分岐で指定
$post_id = get_the_ID(); //投稿IDを取得
$my_title = get_post_meta( $post_id, 'my_title', true ); //カスタムフィールドの値を取得
if( $my_title ){ //カスタムフィールドに値がある時
return esc_html( $my_title ); //エスケープして出力
}
}
@mypacecreator
mypacecreator / functions.php
Last active December 15, 2021 08:03
WordPress4.1以降でカスタムフィールドを使い、投稿ごとにタイトルタグを自由に編集するフィルターフックその1
<?php
//コピペするなら3行目から↓
function mypace_custom_title( $title ){
if( is_singular() ){ //タイトルタグカスタマイズの範囲を条件分岐で指定
$post_id = get_the_ID(); //投稿IDを取得
$my_title = get_post_meta( $post_id, 'my_title', true ); //カスタムフィールドの値を取得
if( $my_title ){ //カスタムフィールドに値がある時
return esc_html( $my_title ); //エスケープして出力
}
}
@mypacecreator
mypacecreator / functions.php
Last active December 15, 2021 08:02
WordPress4.4でタイトルタグのセパレータが' - 'になったのを' | 'に戻す
<?php
//コピペするなら3行目から↓
function mypace_custom_title_separator( $sep ){
$sep = '|';
return $sep;
}
add_filter( 'document_title_separator', 'mypace_custom_title_separator' ); //フィルターフックで処理を上書き
@mypacecreator
mypacecreator / functions.php
Last active December 15, 2021 08:01
meta, title関連でよく頼まれるやつ
<?php
//og:titleにサイト名を入れたいと言われた時用
function custom_open_graph_title( $og_tags ) {
if( is_home() ){
$og_tags['og:title'] = 'ブログ|' . get_bloginfo( 'name' );
} elseif ( !is_front_page() ){
$og_tags['og:title'] .= '|' . get_bloginfo( 'name' );
}
return $og_tags;
}
@mypacecreator
mypacecreator / functions.php
Last active December 15, 2021 08:01
WordPress4.4でカスタムフィールドを使い、投稿ごとにタイトルタグを自由に編集するフィルターフックその2(サイト名はそのまま使う)
<?php
//コピペするなら3行目から↓
function mypace_custom_title( $title ){
if( is_singular() ){ //タイトルタグカスタマイズの範囲を条件分岐で指定
$post_id = get_the_ID(); //投稿IDを取得
$my_title = get_post_meta( $post_id, 'my_title', true ); //カスタムフィールドの値を取得
if( $my_title ){ //カスタムフィールドに値がある時
$title['title'] = esc_html( $my_title ); //ページタイトルの部分のみ上書き
return $title;
}
@mypacecreator
mypacecreator / relatedlink.php
Created March 10, 2021 01:56
改行、カンマ区切りで入力されたカスタムフィールドの値を分解してループで出力(昔やったやつ)
@mypacecreator
mypacecreator / private-debug-log.php
Created December 20, 2018 02:28 — forked from webaware/private-debug-log.php
Enable WordPress debug log to a private folder not accessible from the web. See http://wordpress.stackexchange.com/q/84132/24260 for details and motivations. NB: currently needs to be manually edited to specify the private folder path;
<?php
/*
Plugin Name: Private Debug Log
Description: Enable debug log to a private folder not accessible from the web
Version: 0.0.1
Author: WebAware
Author URI: http://www.webaware.com.au/
*/
/*
@mypacecreator
mypacecreator / mtk
Last active July 30, 2018 10:36 — forked from ysugimoto/mtk
mtkするやつ
#!/bin/sh
echo '玉子とじラーメン 730円(大盛900円)'
echo '玉子とじ担々麺 850円(大盛1030円)'
echo 'もやし麺 850円(大盛1030円)'
echo 'ワンタン麺 850円(大盛1030円)'
echo '叉焼麺 850円(大盛1030円)'
echo '天津麺 850円(大盛1030円)'
echo '五目麺 850円(大盛1030円)'
echo '替玉 180円'
@mypacecreator
mypacecreator / functions.php
Last active March 27, 2018 09:00
wp_list_categories の出力で、カレント表示のclass名の変更と、a要素の内側にさらにspanを入れる
<?php
/**
* wp_list_categories の出力を支給HTMLに合わせて変更
* カレント表示のclass変更、a要素の内側にさらにspanを入れる
*
* @param string $output
*
* @return string
*/
function my_wp_list_categories( $output ) {