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でYouTube動画に共有ボタンをオーバーレイ表示する方法

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

動画はユーザーのエンゲージメントを高める最良の方法の一つです。最近、あるユーザーから、人気サイトUpWorthyのように動画に共有ボタンのオーバーレイを作成する方法について質問を受けました。この投稿では、WordPressでYouTube動画にオーバーレイとして共有ボタンを追加する方法を紹介します。

How to Add Share Buttons as Overlay on YouTube Videos in WordPress

YouTube動画に共有ボタンをオーバーレイ表示する

これにはいくつかの方法があった。ほとんどの方法では、動画を追加するたびにHTMLコードを貼り付ける必要がある。その代わりに、私たちはこのオーバーレイ効果を自動化するショートコードを作成することにしました。

以下のコードをサイト固有のプラグインまたはテーマのfunctions.phpファイルにコピー&ペーストするだけです:

[cbk1]

このコードは、動画にTwitterとFacebookの共有リンクを自動的に追加するショートコードを作成します。これらのボタンは、ユーザーが動画の上にマウスを持ってきたときにのみ表示されます。他のソーシャル・メディア・チャンネルも追加できます。

このショートコードを使用するには、ショートコードにYouTube動画のIDを次のように追加するだけです:

[SKX1]

YouTube動画のIDは、URL文字列から取得できます。このように:

Finding the YouTube Video ID

動画を追加すると、YouTubeの動画と、FacebookやTwitterで動画を共有するためのプレーンテキストのリンクが表示されます。これらのリンクにはすべてスタイルが設定されていません。

そこで、これらのリンクにスタイルを付けてボタンを作成し、見栄えを少し良くしてみましょう。また、これらのボタンを非表示にして、ユーザーが動画コンテナ上にマウスを置いたときにのみ外観が表示されるようにします。そのためには、子テーマのスタイルシートに以下のCSSを追加します。

[cbk2]

これですべてです。これでWordPressのYouTube動画に共有ボタンがオーバーレイ表示されるようになります。

WordPressでYouTube動画のプレイリストに共有ボタンをオーバーレイ表示する

この投稿を公開した後、多くの読者から、このコードをどのように変更すれば動画だけでなくYouTubeのプレイリストでも使えるようになるのか、という質問がありました。WordPressサイトにプレイリストだけでなくYouTube動画も埋め込む場合は、このコードを代わりに使用してください。

[cbk3]

上記のコードを使用すると、共有ボタンをオーバーレイしてプレイリストを追加することもできます。プレイリストを表示するには、ショートコードに動画IDとプレイリストIDを次のようにプロバイダーする必要があります:

[SKX2]

動画 ID とプレイリスト ID は、YouTube のプレイリストにアクセスして URL からリスト ID をコピーすることで取得できます:

Getting YouTube Video and Playlist ID from URL

YouTube動画の共有ボタン・オーバーレイにWordPress投稿リンクを追加する方法

この記事を公開した後、一部のユーザーから、共有ボタンでYouTube動画のリンクではなく、WordPress投稿のリンクを共有したいという要望がありました。そのためには、共有ボタンの動画URLをWordPress投稿のパーマリンクに置き換える必要があります。functions.phpまたはサイト固有のプラグインでこのコードを使用してください:

[cbk4]

CSSやショートコードスニペットは、必要に応じて自由に変更してください。動画をさらに最適化するには、FitVids jQueryプラグインを使ってYouTube動画をレスポンシブにすることができます。また、動画の最後に表示される関連動画をオフにしたり、YouTube動画のサムネイルからアイキャッチ画像を作成することもできます。

この投稿がWordPressでYouTube動画にカスタマイザー共有ボタンを追加するのにお役に立てば幸いです。どのソーシャルメディア・チャンネルを動画に追加する予定か、以下にコメントを残してお知らせください。

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 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

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

  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. Tracy says

    considering this is six years later I’m not really expecting a reply but, on the last shortcode you say to put in the wordpress url instead of the youtube but you don’t say what that code is or where to put it. Can you please keep in mind that very new beginners aren’t just going to know how to do this?

    • WPBeginner Support says

      Apologies for any confusion, we will be sure to endeavor to improve our wording in the future to make this more clear

      管理者

  3. Craig says

    “Most ways would require you to paste a bits of HTML code every time you add a video”

    I’d like to learn this way…. how is it done?

    Thanks

  4. Martin Dekker says

    I’m after a different still image from a youtube video that I have on my site. The one the owner of the video has I don’t like and I’ve heard you can pick a image from the video time line to become your still image ones video ends. Since its not my video I need to beable to do this in the embed iframe code.

    Is this possible and if so could you give me the code. Thank you

  5. Tizy says

    Hello,
    this is an incredible tutorial. It’s possible to show share button at the end of the youtube video and how? Thanks in advance for your help.

  6. WPBeginner Staff says

    Dave, we updated the article to include a method that will share your post link instead of youtube video. Follow the instructions in the section “Adding WordPress Post Link in Share Button Overlay on YouTube Videos”.

    • Dave says

      I was going to go back and edit my comment because I had a “D’oh” moment and noticeed I never activated the site plugin. I wasn’t able to edit because my comment needed to be approved.

      When I did activate it my facebook and twitter share options didn’t overlay the video. They were below the video.

      I don’t know, maybe I did something wrong in the process.

      I like your site and will continue to come back for more great articles.

  7. Christenger says

    This is a great solution, but I have a weird problem. Some IDs works but others not.

    For example, this ID works for me [wpb-yt video=”7vJdBec_B6A”] but this other not [wpb-yt video=”CYveDEem5VA”]

  8. Rednasil says

    Hi guys, thanks for the tutorial.. I got this working in no time on my site.

    But I’m using Yoast’s video seo plugin, and I noticed that it’s not recognizing youtube videos embedded with the shortcode.

    Is there a way to make this happen? Perhaps a work-around where you don’t need to use shortcodes??

  9. Mat says

    Hi everybody,

    How can I add “Share Buttons as Overlay on YouTube Videos” with a Youtube embed inside the Revolution Slider?
    In which php and css files should I paste the codes?

    Thank your help is very appreciated!!

    Mat

  10. Jay says

    Hey there — really appreciate the post.

    I’m trying to modify the functions.php snippet so the share/tweet buttons will refer to my site instead of the youtube.com site. Unfortunately I’m having all sorts of problems. Can you help or point me to somewhere that can help?? I’ve been messing with it for an hour with no progress.

    Really glad you posted this. Its incredibly useful!!

  11. Ike Brown says

    Please when i click on the link does not work. the buttons show up but when you click on it nothing happens

  12. Martin says

    I have created this plugin now 27 times and still it doesnt work at all! I really need this function, could you please explain this again and step by step. Please avoid to start with “just do..” because I am a real newbie and when I sit here I dont know anything.. I have already followed your functions.php tutorial and my site crashed completely. I under stand you are offering a great support here, awesome! Thumbs Up!! Super!!! But please understand that this is really frustrating to create and follow steps so many times and no result. This plugin does not appear in my wp install at all.

    • Martin says

      “just copy it in functions.php..” you know, where in functions.php?? on top where it starts with 1 or on the bottom where there are numbers 300 and so forth?? or in the middle somewhere? Thank you <3

      • Martin says

        sure, no problem to install plugins. I have also fixed this myself in the end, but the result was just so so, its not looking very neat tbh. So I deleted it again. I was searching for other solutions but they dont seem to exist, everything is related to “making money” or “locking content” .. why would anyone like a page for locking it up? I really need this plugin and I don’t have any money to hire people. Please offer me some support via email, you could explain to me how I can style the whole thing so it looks better. Please Please Please! I would really appreciate this. Thank you <3

    • Patrycja says

      The same here. I tried just adding it to functions.php, then with site-specific plugin. Nothing. Nada. And I really would love it to work. Does it work on all themes?

  13. Skip says

    Awesome code which I’ve adapted and implemented on a test page including Google+ too. I know the thrust isn’t CSS but just wanted to make the point that I think opacity 0 is a really bad idea as more and more browsing is done on touchscreen where there is no hover event and the buttons would never be seen. I would either forget opacity effects altogether or set an initial opacity at 0.5 or use media queries to target different devices with individual opacity settings.

  14. Pam Simmons says

    This is very helpful. It appears that the share buttons in this example actually share the YouTube video link, rather than the page containing the embeded video like the UpWorthy button overlays do. How would one alter the code to grab the page permalink rather than the youtube link?

    • Dave says

      I just wasted 30 minutes of my life. I did everything the tutorial said to do and it just showed a short code on my post. But even if it did work, according to the comment I am replying to, it would have driven traffic to youtube and not my site. :-(

  15. Chris says

    This is good. What about using a playlist ID in the short code?

    Most people use static videos on posts but on home pages we use playlists.

    How could this code be modified to add the share buttons over playlist videos?

    I.e. to work with the YouTube Channel Gallery plugin.

    BTW – UNDER the code your text says this: “The following code creates a shortcode that automatically adds twitter and facebook buttons to your videos.”

    Shouldn’t that say “…PRECEDING code…”?

  16. Krish Murali Eswar says

    Nice one. I am generally averse to changing anything at the code level. This seems like a straightforward plugin candidate. Are you sure there is no plugin?

  17. May says

    This looks great. Could you give a very simple step by step instruction on how to install it – perhaps on YouTube?

  18. Steven says

    Great article!

    How do you add this shortcode now to the html shortcode editor that appears on the tinymce bar?

  19. Steve Wharton says

    Pretty cool code. Looking forward to playing around with it, and adding to my new site. Thanks!

  20. Tom Horn says

    Is there a way to utilize a plugin to add this code so we don’t screw things up if we’re not use to working under the hood? Thanks for this, I have seen things like this before and really wanted to know how to do it.

  21. Pam Blizzard says

    Thank you for sharing this, is an elegant solution.
    Do you think it might work for YouTube Playlists as well, with the “PLxxxetc” syntax?

  22. Zimbrul says

    This is quite a cool thing to do on your Youtube videos: sharing buttons. I also like those floating buttons on images added by FooBox

  23. Pam says

    This is awesome, thank you!
    Do you think it could be adjusted to work with playlists as well as individual videos?

返信を残す

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