WordPressのテンプレートの修正方法
画面に情報を表示する際の仕組みについて調べる
①画面表示時にフィルターフックで様々な処理が実行される
画面表示テンプレート(.php)では「the_content();」というフィルターフックが実行される。
②フィルターフックは、下記のファイルで事前に定義している
フィルターフックで、呼び出された時に何をするか定義している。
wp-includes\default-filters.php
add_filter( ‘the_content’, ‘do_blocks’, 9 );
add_filter( ‘the_content’, ‘wptexturize’ );
add_filter( ‘the_content’, ‘convert_smilies’, 20 );
add_filter( ‘the_content’, ‘wpautop’ );
add_filter( ‘the_content’, ‘shortcode_unautop’ );
add_filter( ‘the_content’, ‘prepend_attachment’ );
add_filter( ‘the_content’, ‘wp_make_content_images_responsive’ );
③add_filter()のパラメータで起動する関数を動的に変更
the_contentがパラメータに定義された場合は、下記の関数が呼ばれる。
ただ、この関数を修正することは、基本ないと思われる。
wp-includes\blocks.php
function the_content( $more_link_text = null, $strip_teaser = false ) {
$content = get_the_content( $more_link_text, $strip_teaser );
画面表示で使われているテンプレート
画面レイアウトやスタイルを変えるために、どのファイルを修正したらよいのか調査した。
画面テンプレートの格納先
wp-content\themes\テーマ名\template-parts
トップ画面(記事一覧画面) のテンプレートファイル(.php)
content-excerpt.php
記事詳細画面のテンプレートファイル(.php)
content.php
スタイルシートの格納先
下記のCSSにほぼ全部のスタイルが記載されている。このファイルだけ修正すればよい。
wp-content\themes\テーマ名\style.css
以上