LoginSignup
1
0

More than 1 year has passed since last update.

【WordPress】画像までのパスを簡略化する

Posted at

wp-content/themes/example-theme/imagesディレクトリに配置したtest.pngという画像を表示したい場合、以下のように記述することで画像までのパスを出力することができます。

<img href="<?php echo get_template_directory_uri() . '/images/test.png'; ?>">

function.phpに以下を追記することで簡略化できます。

/**
 * 画像までのパスの簡略化
 */
function get_theme_img($img_name)
{
	$content = esc_url(get_template_directory_uri()) . '/images/' . $img_name;
	return $content;
}
<img href="<?php echo get_theme_img('test.png') ?>">
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0