WordPress のサイトを構築する際に便利なので、function.php に書いておきたいものの覚え書き。
WordPress のバージョンを消す
今時では攻撃に備えるなどの理由でバージョンを隠す意味もないですが「うわ、こんな古いの使ってるんだ!?」とか思われるのもイヤなのでバージョンを隠す方法。
remove_action('wp_head','wp_generator');
子カテゴリの専用テーマファイルが無い場合は親カテゴリのテーマファイルを使う
add_filter( 'category_template', 'my_category_template' );
function my_category_template( $template ) {
$category = get_queried_object();
if ( $category->parent != 0 &&
( $template == "" || strpos( $template, "category.php" ) !== false ) ) {
$templates = array();
while ( $category->parent ) {
$category = get_category( $category->parent );
if ( !isset( $category->slug ) ) break;
$templates[] = "category-{$category->slug}.php";
$templates[] = "category-{$category->term_id}.php";
}
$templates[] = "category.php";
$template = locate_template( $templates );
}
return $template;
}