ワードプレスTips

ワードプレスの使い方やカスタマイズを備忘録としてまとめています。

アイキャッチの表示関連

テーマの作成時などでアイキャッチをループ内で表示したい時のテンプレートタグ

 

ループ内でアイキャッチの表示

the_post_thumbnail('thumbnail');

テンプレートタグ/the post thumbnail - WordPress Codex 日本語版

 

the_post_thumbnail();                     // パラメータなし -> 'post-thumbnail'
 
the_post_thumbnail( 'thumbnail' );        // サムネイル (デフォルト 150px x 150px :最大値)
the_post_thumbnail( 'medium' );           // 中サイズ   (デフォルト 300px x 300px :最大値)
the_post_thumbnail( 'large' );            // 大サイズ   (デフォルト 640px x 640px :最大値)
the_post_thumbnail( 'full' );             // フルサイズ (アップロードした画像の元サイズ)
 
the_post_thumbnail( array( 100, 100 ) );  // 他のサイズ

フィルターフック

・画像の出力時

image_send_to_editor

add_filter( 'image_send_to_editor', 'img' );

function img($html){

return $html;

}

・画像の挿入時

post_thumbnail_html

add_filter( 'post_thumbnail_html', 'img' );

function img($html){

return $html;

}