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

Beginner’s Guide: Så här centrerar du ett videoklipp i WordPress

När vi precis hade kommit igång med WordPress kunde något så enkelt som att centrera en video vara förvånansvärt frustrerande.

Efter att ha hjälpt många nybörjare genom WPBeginner insåg vi att vi inte var ensamma – det är en av de vanligaste formateringsfrågorna vi får.

Den goda nyheten är att det har blivit mycket enklare att centrera videor i WordPress, särskilt med blockredigeraren. Men vi ser fortfarande många människor som kämpar med detta, särskilt när de arbetar med inbäddade videor från YouTube eller Vimeo.

I den här nybörjarvänliga guiden visar vi dig de enklaste sätten att centrera dina videor i WordPress.

How to center align a video in WordPress

Varför centrerat inrikta videoklipp i WordPress?

När du bäddar in en video i WordPress justeras den automatiskt till vänster som standard. Detta beror på att videor är externt innehåll som är inbäddat i innehållet, så WordPress kan inte gissa hur du vill visa dem.

Som en bästa praxis justerar WordPress automatiskt videon till vänster, så att du kan justera justeringen om det behövs.

Genom att rikta in videon i mitten får användarna en bättre upplevelse när de tittar på ditt innehåll. På så sätt kommer du inte att ha märkbart tomt utrymme på ena sidan av sidan, vilket kan ge ett oprofessionellt utseende.

Dessutom, om du uploadar videoklipp direkt till WordPress, kommer samma sak att hända med dem om deras bredd är mindre än ditt content area. WordPress justerar dem till vänster som standard.

Med detta sagt, låt oss se hur du enkelt kan centrera en video på en WordPress-webbplats. Vi kommer att täcka både blockredigeraren och den klassiska redigeraren, så du kan klicka på länkarna nedan för att hoppa vidare till något avsnitt.

Så här centrerar du videoklipp i WordPress Content Editor

Om du vill att ditt videoklipp ska fylla bredden på ditt innehållsområde är det bästa sättet att göra detta genom att lägga till en YouTube- eller Vimeo video URL direkt i WordPress content editor.

Först måste du edit ett post eller en page eller add new. När du är i content editor klistrar du helt enkelt in länken till videoklippet. WordPress kommer att embedda videoklippet automatiskt.

Paste video embed code in block editor

Välj sedan blocket Video och klicka sedan på alternativet “Change Alignment”. Från dropdown-menyn kan du välja positionen för videoklippet.

WordPress låter dig välja mellan följande inriktningar:

  • Stor bredd
  • Full bredd
  • Justera vänster
  • Rikta in mitten
  • Justera höger

Gå vidare och välj alternativet “Justera centrerat”.

Align the video to the center

Efter det kan du previewa och publicera din page eller post.

Videoklippet kommer nu att vara centrerat.

Center aligned video preview

Av en eller annan anledning kan du dock behöva använda inbäddningskoden. I så fall måste du lägga till lite enkel HTML runt din videos inbäddningskod.

Först måste du klicka på de 3 prickade iconerna i videoklippet block. Efter det kan du välja alternativet “Edit as HTML” från dropdown-menyn.

Edit as HTML

Följaktligen kan du enter följande HTML-kod runt embed-koden för videoklippet:

1
2
3
4
5
<div style="text-align:center;">
 
/// your video embed code goes here
 
</div>

Så här ser din inbäddningskod ut med den anpassade HTML-koden.

Preview of custom HTML code

Du kan nu spara dina ändringar och förhandsgranska inlägget eller sidan. Nu vet du hur du centrerar en video i HTML.

En annan metod är att manuellt öka bredden på din video så att den passar innehållsområdet. För att uppnå detta måste du lägga till eller ändra parametern “width” i din inbäddningskod:

1
<iframe width="760" height="315" src="https://www.youtube.com/embed/4YpyiJ05YOg" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Hur man centrerar och justerar videoklipp i Classic Editor

Om du använder Classic-redigeraren kan du centrera videor genom att redigera ett inlägg eller skapa ett nytt.

När du är i redigeringsverktyget växlar du till textvyn. Skriv nu in följande HTML-kod:

1
2
3
4
5
<div style="text-align:center;">
 
/// your video embed code goes here
 
</div>

Se bara till att ersätta “your video embed code goes here” med koden för ditt videoklipp.

När det är gjort kommer det att se ut ungefär så här:

Center align videos in classic editor

You can now preview and publish your page.

Besök helt enkelt your website för att se det centrerade videoklippet.

Center aligned video classic editor preview

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du centrerar en video i WordPress. Du kanske också vill se vår guide om hur du lägger till specialtecken i WordPress-inlägg och viktiga tips för att använda kortkoder i 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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial 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.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

18 kommentarerLeave a Reply

  1. A Owadud Bhuiyan

    if I have three YouTube videos, can I show them in the same row by adjusting the width?

    Thanks for the tips.

  2. Tom Z

    Thanks for posting this, it worked and was very helpful!

    • WPBeginner Support

      Glad to hear our guide was helpful!

      Admin

  3. Marc

    Thanks for the info!! :)

    • WPBeginner Support

      You’re welcome!

      Admin

  4. S

    I’m trying to center a gif that I’ve embedded and the new editor doesn’t let me edit the HTML of this type of content. How can I center this?

  5. Diane

    How does this work when using the Gutenberg Editor’s You Tube embed block? I tried both ways you described, but either are working.

    • WPBeginner Support

      With the YouTube embed block there should be a section when you select the block to set a specific alignment that you can use.

      Admin

  6. Marshall

    The tip sounds great, but every time I “save” and come back, it’s gone.

    • WPBeginner Support

      You may want to try to clear any caching on your site to ensure you’re not seeing the cached version of the page.

      Admin

  7. Himanshu

    You offer a lot of outstanding tricks and videos to go along. I have subscribed to your email newsletter and have seen many videos for my new website. However, your trick on aligning the video on the center did not work. Here is the issue: I shot a 15-sec video on iPhone converted into mp4 and uploaded on my host server, shows up in my WordPress galley. Since the video occupies the entire width, I changed the video width and height to a 1/3 each. Then I pasted the align center code you showed on your video at https://www.wpbeginner.com/beginners-guide/beginners-guide-how-to-center-align-a-video-in-wordpress/#respond

    But the video does not align in the center. When I look at the video in the frontend editor, I see a box with a blue line that occupies the entire width even when the video is 1/3 the width. Looks like this blue line box cannot be made smaller with any code. Is that true? Any tricks in your bag of trick that you can share?

    You have been great and thanks for your videos. you made my life so much easier.

    • WPBeginner Support

      Hi Himanshu,

      You can try switching to the HTML editor to add the code. Hopefully it would work then.

      Admin

  8. Young

    thank you for the article! very helpful

  9. Deb

    Thank you, this article was very helpful!

  10. Carole

    Adding the div html around the embed code worked like a charm. Thanks!

  11. bilikid

    Thanks for this. Definitely plan on trying it!!

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.