LoginSignup
2
2

More than 5 years have passed since last update.

WordPress: アイキャッチ画像のURLを取得する function【functions.php】

Posted at
functions.php
/**
 * アイキャッチ画像のURLを取得
 *
 * @param string $size アイキャッチ画像サイズの名前
 * @param string $type echoするなら 'e' を第二引数に渡す
 * @return string アイキャッチ画像のURL
 */
function get_featured_image_url($size, $type = '')
{
  $image_id  = get_post_thumbnail_id();
  $image_url = wp_get_attachment_image_src($image_id, $size, true);

  if ($type === 'e')
  {
    echo $image_url[0];
  }
  else
  {
    return $image_url[0];
  }
}
2
2
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
2
2