Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressで投稿サムネイルのURLを取得する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressの投稿のおすすめ画像のURLを取得する必要がありますか?

これは、独自のWordPressテーマや子テーマを開発している場合や、初期設定でアイキャッチ画像が表示されないテーマに調整を加えている場合に便利です。

この投稿では、WordPressで投稿サムネイルのURLを取得する方法を紹介する。

How to Get the Post Thumbnail URL in WordPress

なぜWordPressで投稿サムネイルのURLを取得するのか?

WordPressブログの投稿にサムネイルやおすすめ画像を追加することで、視覚的な面白さが加わり、より魅力的に見えるようになります。さらに詳しくは、WordPressでおすすめ画像や投稿サムネイルを追加する方法をご覧ください。

ソーシャルメディアで投稿を共有したい場合、アイキャッチ画像やその他の画像へのリンクを投稿にコピーする必要があるかもしれません。その方法は、WordPressでアップロードした画像のURLを取得する方法のガイドで順を追って紹介しています。

しかし、独自のテーマを開発したり、既存のテーマを修正する場合は、投稿サムネイルのURLを取得して、独自のカスタム・マークアップで使用できるようにする必要があるかもしれません。この場合、テーマファイルにコードスニペットを追加する必要があります。

WordPressで投稿サムネイルのURLを取得する方法を見てみよう。

WordPressで投稿サムネイルのURLを取得する方法

投稿サムネイルのURLを取得するには、カスタマイズするテーマテンプレートにコードを追加する必要があります。さらに詳しく知りたい方は、WordPressでカスタムコードを追加する方法をご覧ください。

単純に投稿サムネイルを表示したいのであれば、WordPressのループの中で作業しているテンプレートにこのPHPコードを貼り付ければよい:

echo get_the_post_thumbnail(get_the_ID(),'medium');
Code Snippet to Display Post Thumbnail

しかし、独自のカスタム・マークアップを使って投稿サムネイル画像を表示したり、テーマでサムネイルを使ったりしたいので、投稿サムネイルのURLを取得する必要があります。

代わりにこのコードをテンプレートに貼り付ける必要があります:

echo get_the_post_thumbnail_url(get_the_ID(),'medium');
Code Snippet to Display Post Thumbnail URL

このコードは単にアイキャッチ画像のURLを表示します。その後、投稿サムネイルのURLを使用するようにコードをカスタマイズすることができます。

サムネイルのサイズもカスタマイズできます。medium’を’thumbnail’、’medium-large’、’large’、’full’などの初期設定の画像サイズに置き換える必要があります。

または、作成した画像サイズを追加して使用することもできます。カスタマイザーを使用する場合は、必ずサムネイルを再生成してください。

このチュートリアルで、WordPressで投稿サムネイルのURLを取得する方法を学んでいただけたら幸いです。また、最適なウェブデザインソフトウェアの選び方や、WordPressを使ってブログでお金を稼ぐ方法をご紹介しています。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

18件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Kiran says

    I have designed a website using wordpress. Currently featured image is showing description section.

    But i want to show featured image url in rss feed.

    How to add featured image (media:thubnail) url in rss feed?

    Please help…

  3. Mohan Krishna says

    Your Site is giving awesome tips but i suggest you to provide demos of the respective codes how it looks like after making the changes as you said because users like me can have a look over that and find if it suits best or not also by the way your visitors can increase by double.

  4. TracyDempsey says

    Hi there, I’m searching for how to manually get the URL, but keep finding posts with code for fetching the URL. I’m using Thesis, and I’ve used the WordPress image editor on some post images to create a cropped, square thumbnail image for my category pages’ excerpts/teasers. But, when I paste the image URL into Thesis’ thumbnail URL field, it doesn’t recognise the cropped thumbnail, but crops the original image (thereby skewing the aspect ratio). So I’m just trying to find the direct URL for the thumbnail of the source image – can you help?? Thanks in advance!

  5. Wynand says

    I dont know if this is the correct page to post this, but what i would like to do is the following:

    I have many websites, I would like to display a thumbnail of each in a wordpress page, by just adding the url to that page, or some code surrounding the url

    Can anybody help

  6. Nicola says

    Thanks for writing this tutorial, i don’t know why but the code you wrote never worked for me, and i know it is even available in the codex, i tried it with several loop configurations but no luck.

    Recently i managed to make it work by using it in conjunction with another function: get_post_thumbnail_id()

    ID ) );
    ?>
    <img src="” alt=”” />

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。