自分なりにテーマ作成でチェックしたい項目の覚え書き。まだまだありそうだけど、随時追記していく。
index.php
language_attributes()
<html <?php language_attributes(); ?>>
charset
<meta charset="<?php bloginfo('charset'); ?>">
stylesheetへのリンク
<link rel="stylesheet" href="<? echo get_stylesheet_directory_uri(); ?>/style.css" />
でもできそうだけど、functions.phpで設定するのが推奨。
ヘッダフック
wp_head();
ブログのURL
bloginfo('url');
サブタイトル
bloginfo('description');
シングルページ判定
if(is_single()): endif;
次の投稿へのリンク
next_posts_linkだと素っ気ないので、get_next_post()を使ってオブジェクト取得。そこから先はやりたい放題。
$next_post = get_next_post(); if(!empty( $next_post )): $next_post_title = apply_filters( 'the_title', $next_post->post_title ); $next_post_category=get_the_category($next_post->ID);//配列 $next_post_category_slug = $next_post_category[0]->category_nicename;
<div><?php $prev_post = get_previous_post(); if(!empty( $prev_post )): $prev_post_title = apply_filters( 'the_title', $prev_post->post_title ); $prev_post_category=get_the_category($prev_post->ID); $prev_post_category_slug = $prev_post_category[0]->category_nicename; ?> <p class="c-category__item"><?php echo $prev_post_category_slug; ?></p> <?php previous_post_link('%link','%title'); ?> <?php endif; ?> </div>
ログイン/アウトのリンク
wp_loginout();
フッターフック
wp_footer();
functions.php
タイムゾーン設定
date_default_timezone_set('Asia/Tokyo');
テーマサポート
titleタグとRSSリンクを許可。
add_theme_support('title-tag'); add_theme_support('automatic-feed-links');
サイドバー登録
add_action('widgets_init',function(){ register_sidebar(array( 'name'=>'sidebar1', 'id'=>'sidebar-1', 'before_widget' => '<nav id="%1$s" class="widget-cintainer %2$s">', 'after_widget' => '</nav>', 'before_title' => '<h3 class="widget-title hide">', 'after_title' => '</h3>', )); });
stylesheet
add_action('wp_enqueue_scripts',function(){ wp_register_style('app',get_template_directory_uri().'/css/app.css',array(),'20170313','screen'); wp_enqueue_style('app'); });
カスタムメニュー
CSS有効化
ウィジェット OfficeCasebook Categories
comments.php
モジュール化
get_template_part('foo','bar');
foo-bar.phpを取得する。
Adsense
jQuery(document).ready(function(){(adsbygoogle = window.adsbygoogle || []).push({})})
.adsbygoogle {width:100%;}