(WP)投稿ページや固定ページでテーマの画像フォルダを呼び出す時ののパスを短くする!
なんとも、長いタイトルですが...
いつも使うので、MEMOしときます。
ワードプレスで、投稿ページや固定ページをHTML編集している時、
テーマフォルダの/imges/に入れた画像を呼び出す時に
<img src="/wordpress/wp-content/themes/〇〇/images/image.jpg">
みたいな感じで、いちいち書くのって面倒くさいですよね。
これがなんと!
<img src="images/image.jpg">
これでOKになります。
functions.phpに以下のコードを記述してください。
<親テーマの場合>
function imagepassshort($arg) {
$content = str_replace('"images/', '"' . get_bloginfo('template_directory') . '/images/', $arg);
return $content;
}
add_action('the_content', 'imagepassshort');
<子テーマの場合>
function imagepassshort($arg) {
$content = str_replace('"images/', '"' . get_bloginfo('stylesheet_directory') . '/images/', $arg);
return $content;
}
add_action('the_content', 'imagepassshort');
以上ですー。