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

Så här addar du thumbnails för YouTube-videor i WordPress

Har du sett populära webbplatser som använder sina YouTube video thumbnails på front page på sin site? Om du run en videokanal på webbplatser som YouTube, Vimeo eller andra, kan du också visa en videominiatyr för alla posts som innehåller videor på front page och archive pages på din blogg. I den här artikeln visar vi dig hur du lägger till thumbnails för YouTube-videor i WordPress.

An example of video thumbnails in WordPress

Video thumbnails och inläggsminiatyrer i WordPress

WordPress kommer med built-in funktionalitet för att add featured images eller inläggsminiatyrer, och de flesta WordPress teman stöder denna funktion. Men om du vill lyfta fram ditt videoinnehåll från YouTube, då vill du visa upp det innehållet med video thumbnails. Den här artikeln hjälper dig att göra det genom att använda WordPress standardfunktionalitet för inläggsminiatyrer.

Konfigurera tillägget Video Thumbnails i WordPress

Det första du behöver göra är att installera och aktivera pluginet Video Thumbnails. När du har aktiverat pluginet måste du gå till Settings ” Video Thumbnails för att konfigurera plugin-inställningarna.

Setting up video thumbnails

På vyn Settings rekommenderar vi att du väljer att store thumbnailen i ditt mediabibliotek. Detta kommer att minska externa http requests på din site, och dina pages kommer att hämta snabbare. Under post types section kommer pluginet att visa posts, pages, och custom post types om du har några på din website. Välj de post typer du vill att plugin ska skanna efter videoklipp länkar. Det sista alternativet på den här sidan är att välja ett custom field. Vissa videoplugins för WordPress sparar URL:er till videoklipp i ett custom-fält, och om du använder sådana tillägg måste du ange det custom-fältet här. Efter det klickar du på knappen Save Changes.

På sidan Settings ser du också tabben Providers. Om du använder Vimeo för att dela dina videoklipp måste du skapa en app på Vimeo och sedan ange klient-ID, klienthemlighet, access token och access token secret-värden här.

Adding Vimeo app credentials

På fliken Mass Actions kan du skanna dina publicerade posts efter videor och generera video thumbnails för dem. Pluginet ger också en knapp för att clear alla video thumbnails och ta bort dem som attachment från dina posts.

Scan posts to generate video thumbnails

Skapa video thumbnails i WordPress Posts

Nu när du har konfigurerat pluginet, låt oss skapa en video thumbnail genom att lägga till en video URL i en WordPress post. För att göra det måste du skapa eller redigera ett WordPress-inlägg och add to your video URL i postens redigerings area. När du publicerar inlägget kommer du att se att pluginet har genererat en video thumbnail åt dig och lagt till den i ditt inlägg.

Adding a video in WordPress Post and Generating a Video Thumbnail

Displaying a Video Thumbnail in your WordPress Theme

Video thumbnails plugin använder WordPress inläggsminiatyrer-funktionalitet. De flesta WordPress teman är inställda för att automatiskt visa inläggsminiatyrer. Detta innebär att ditt theme automatiskt kommer att visa video thumbnailen tillsammans med ditt inläggsminiatyr eller excerpt. Men om ditt tema inte visar video thumbnails, måste du editera dina theme-filer och add to denna kod till den template där du vill visa thumbnail.

<?php the_post_thumbnail(); ?>

Hur man lägger till en Play-knapp på video thumbnailen i WordPress

Nu när du utan problem har genomfört och displayed videominiatyrer i dina WordPress-poster, kanske du vill skilja dina vanliga inläggsminiatyrer från dina video thumbnails. Detta kommer att låta dina användare veta att det finns ett videoklipp i posten, och de kan klicka på knappen Spela upp för att viewa videoinlägget. Vi visar you hur man använder villkorsstyrda taggar för att skilja mellan video thumbnails och vanliga inläggsminiatyrer och add to en play-knapp.

För att använda den här metoden måste du se till att du publicerar dina videoklipp under en viss kategori, till exempel Videos. Sedan letar du efter den här kodraden i ditt temas template-filer som gillar index.php, archive.php, category.php eller content.php:

<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>

Nu måste vi ersätta den här koden med följande kod:

<?php if ( in_category( 'video' )) : ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?><span class="playbutton"></span></a>
<?php else : ?> 
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>	
<?php endif; ?>

Denna kod add to <span class="playbutton"?></span> efter inläggsminiatyren endast för posts som är arkiverade under video category. Nästa steg är att ladda upp en image-fil från Media ” Add New vy. Denna image kommer att användas som uppspelningsknapp. När du har uploadat bildfilen kan du obs/observera bildfilens location genom att clicka på Edit-länken bredvid bilden.

Det sista steget är att displaya uppspelningsknappen. Vi kommer att använda CSS för att visa och positionera uppspelningsknappen på video thumbnailen. För att göra det måste du copy and paste den här CSS-koden i ditt temas eller barntemas stylesheet genom att clicka på Appearance ” Editor.

.playbutton {
    background: url('http://example.com/wp-content/uploads/playbutton.png') center center no-repeat;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 74px;
    height: 74px;
    margin: -35px 0 0 -35px;
    z-index: 10;
    opacity:0.6;
}
.playbutton:hover { 
    opacity:1.0;
}

Glöm inte att ersätta bakgrundsbildens URL med URL:en till bildfilen för uppspelningsknappen som du uploadade tidigare. Det är all. Dina video thumbnail-filer bör nu ha en uppspelningsknapp på dem.

Vi hoppas att den här artikeln hjälpte dig att markera dina YouTube-videor med thumbnails i WordPress. För återkoppling och frågor vänligen lämna en comment eller följ oss på Twitter.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

44 kommentarerLämna ett svar

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

    It is amazing that it still works!
    However does somebody know why it is not getting a thumbnail from a YT playlist?
    i´ve several posts with playlist and the image is always a grey ”Video is not found” image

    • WPBeginner Support says

      The plugin was created for videos and not entire playlists, you would need to reach out to the plugin’s author for including playlist functionality.

      Administratör

    • WPBeginner Support says

      You would need to check with the plugin’s support for if that is supported.

      Administratör

  3. Mohammad says

    Hi
    I try to use this plugin but it doesn’t work for me and the developer in support forums doesn’t answer most of the unsolved topics. In debugging page when I try ”Test Markup for Video” I get this error:

    Thumbnail found, but it may not exist on the source server. If opening the URL below in your web browser returns an error, the source is providing an invalid URL. Thumbnail URL:
    what’s the problem?

  4. Neon emmanuel says

    what if i want three parameters, 1 a fall back when there is no thumbnail, two i fall back if it is video, (i.e) adding a play button overlay to it , and three a fall back it it is video with an overlay play icon on it.

  5. franck says

    Hi folks,

    is anybody know how to remove related video when Youtube video is played till the end in video gallery plugin from Huge IT?

  6. Rihan says

    And wordpress 4.0 I add the video (youtube) URL in the post edit area and its showing me a video player :( on the video thumb are i can see this text only (No video thumbnail for this post.) not working!

    any Idea :) thanks

  7. Mauro Scarpa says

    Hi! Great website and post, i have a question, if then I want to share my post on facebook, will appear whit the play button also? Thanks

  8. Piet says

    Cool plugin and tutorial. Instead of showing a play button image, I would like to suggest using a font icon, for example from FontAwesome.

  9. WPBeginner Staff says

    TCB: if you are using WordPress SEO plugin then youc an try this method. Once the video thumbnail plugin has fetched the thumbnail image for your video, you need to find its location in your media library and copy the URL. After that remove the video thumbnail image from the post. In the WordPress SEO meta box on the post editor, click on the social tab, and paste the link next to the facebook image field.

  10. TCB says

    Is it possible to use the video thumbnail as post image on facebook?
    That would be great because I don’t want to the show the picture as featured image.

  11. Megha Verma says

    I am facing a problem as the play button is showing only on the first post….due to absolute position….not on other post’s images…

  12. Sutherland Boswell says

    Great tutorial! As the developer I love to get feedback from users and work on easy solutions for the most requested features. Overlaying a play button and making the video actually play when clicking the thumbnail are two of the most requested features, but they’re both highly dependent on the theme. Learning to modify a theme on your own can be rewarding, so don’t be afraid to give it a shot!

    PS – I hope everyone will check out the pro version!

    • Jesse says

      Hi Sutherland.

      I’ve read such good things about your plugin and I’m eager to try it.

      However, when using your plugin to scan for video files, it finds all 22 videos under the ’video’ page which they are posted. The problem is it isn’t finding any thumbnails.

      After reading your various support replies to similar issues, as well as your instructions, i sought to find out whether my theme (metric, by grandpixels) is using a custom field. I have been unsuccessful in finding this information.

      Do you have suggestions on how to make this work?

      Thanks,

      Jesse

  13. Audee says

    What if I want to display post thumbnail only for posts filed under video ’Post Format’ ?

    Thank you for sharing article about this plugin!

      • Alex says

        Hi Sutherland Boswell,

        i use your plugin for Detube theme, the problem is there is no <a href="”> code line in those files: index.php, archive.php, category.php..
        Do you have any idea or a way to make it work in Detube theme?

        Thanks in advance!

        • Alex says

          i would be so glad if someone has an idea and could answer my question. I’ve been working for many hours to get this code works on Detube, but no succes untill now…
          Could someone here please help me?

  14. Ahmad Rafi Maseer says

    HOw to play directly in thumbnail so the user should not go to post page to play the video???

  15. Sue Anne says

    Thanks SO much for the great instruction on putting a video and video thumbnail on my WordPress blog. It took about 5 minutes and I’m no techie!

  16. Pali Madra says

    Hi!

    Great website and one of my favorite post.

    I had a related question. I’m adding video by placing the URL in the HTML code of the posts but I also want to show a caption below it. Is that possible without using a plugin?

    Thanks in advance

  17. Tiguan says

    The ‘span’ must be placed inside the thumbnail’s hyperlink tags, otherwise the image link over play button will be disabled. So the correct code will be:

    However, it’s a nice tutorial.

  18. gottfrid q. says

    > This will let your users know that there is a video in the post, and they can click on the play button to view the video post.
    I don’t want to disappoint you, but the button (spin) don’t have any click method.
    How exactly this button was supposed to work and how to implement it?

    Thanks for your time.

  19. Akash says

    And. how to implement Play Button in GENESIS Theme? there is no index.php, archive.php, category.php, or content.php file there to add the code.

    Thanks.

  20. Akash says

    But what will be the size of the Video Thumbnail? Will it be same as the image thumbnail already set in the blog?

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.