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

Jak sprawić, by twój film był responsywny w WordPressie dzięki FitVids

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Kiedy osadzasz film w WordPressie, domyślnie nie są one responsywne. Wraz z rozwojem responsywnych motywów WordPress, użytkownicy, którzy przejdą na twoją witrynę na mniejszych ekranach, zobaczą kontenery z filmami, które są rozciągnięte i nieproporcjonalne. W tym artykule pokażemy, jak sprawić, by twoje filmy były responsywne w WordPressie za pomocą FitVids.

Default non-responsive and responsive video embeds in WordPress

FitVids to wtyczka jQuery, która pozwala na responsywne osadzanie twoich filmów. Jeśli chcesz użyć go na swojej witrynie WordPress, wszystko co musisz zrobić, to zainstalować i włączyć wtyczkę FitVids for WordPress. Po włączaniu należy przejść do Wygląd ” FitVids i wpisz klasę selektora CSS. WordPress automatycznie dodaje klasę .wpis do artykułów, więc możesz po prostu z tego skorzystać.

FitVids for WordPress plugin settings

To wszystko, zapisz zmiany i wyświetl podgląd twojej witryny. Będziesz musiał zmienić rozmiar ekranu przeglądarki, aby zobaczyć, jak filmy odpowiednio się dostosowują.

Film poradnik

Subscribe to WPBeginner

Jeśli nie podoba Ci się film lub potrzebujesz więcej instrukcji, czytaj dalej.

Ręczne dodawanie FitVids, aby twój film był responsywny w WordPressie

Jeśli nie chcesz instalować wtyczki FitVids for WordPress, możesz dodać wtyczkę FitVids jQuery ręcznie. Pierwszą rzeczą, którą musisz zrobić, to pobrać i wyodrębnić wtyczkę Fit Vids jQuery na twój komputer. Teraz musisz przesłać wyodrębniony katalog FitVids.js-master do katalogu js twojego motywu.

Musisz połączyć się z twoją witryną internetową za pomocą klienta FTP, takiego jak Filezilla, i otworzyć katalog motywu. Możliwe, że twój motyw WordPress nie ma katalogu js. Jeśli go tam nie ma, musisz go utworzyć, a następnie przesłać katalog FitVids.js-master z twojego komputera.

Wewnątrz katalogu js należy utworzyć nowy plik i nazwać go FitVids.js. Edytuj ten plik i wklej do niego poniższy kod.

(function($) {
  $(document).ready(function(){
    // Ukierunkuj twój .container, .wrapper, .wpis itp.
    $(".wpis").fitVids();
  });
  
  })(jQuery);

Powyższy kod mówi FitVids, aby szukał klasy selektora CSS .wpis. Teraz, gdy masz już gotowe FitVids, nadszedł czas, aby poprawnie dodać javascript w twoim motywie WordPress.

Wystarczy skopiować i wkleić poniższy kod do pliku functions. php twojego motywu:

wp_enqueue_script('fitvids', get_template_directory_uri() . '/js/FitVids.js-master/jquery.fitvids.js', array('jquery'), '', TRUE); 

wp_enqueue_script('fitvids-xtra', get_template_directory_uri() . '/js/FitVids.js', array(), '', TRUE);

.

Gdy to zrobisz, gotowe. Udało ci się sprawić, że twoje filmy WordPress są responsywne.

Mamy nadzieję, że ten artykuł okazał się przydatny. W przypadku uwag i pytań prosimy o pozostawienie komentarza poniżej lub dołączenie do nas na Twitterze i Google+.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

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.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

16 komentarzyZostaw odpowiedź

  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!

    • WPBeginner Support says

      We will be sure to take a look and consider alternatives when we next update this post :)

      Administrator

  2. smithy says

    Not perfect, but with Jetpack, and WP 'out of the box’, this css will make youtube video embeds fit 100% content width responsively – requiring no plugins etc. so very 'compact’. The 'padding’ keeps the aspect ratio.

    span.embed-youtube {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 18px; height: 0; overflow: hidden;
    }

    span.embed-youtube iframe,
    span.embed-youtube object,
    span.embed-youtube embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    }

    If it helps anyone.

  3. Flemming says

    This works perfectly for me (self hosted WP site). I originally used a plugin called Advanced Responsive Video Embedder which is really good but it didn’t play nicely with OptimizePress plugin.

    The FitVids plugin does exactly what I need with no problems (so far!) – thanks so much for writing this post, saved me a headache!

    • Anthony baker says

      OH, it seems this article is for wordpress.org. So confusing. So if I have the premium version of WordPress.com can I add this plugin?

  4. Gabor says

    The other thing is that,in case i set .post-entry /that is for me/

    than all the post will be responsive and the amazon widget that i add will be too.Which expands on the whole post…any workaround?

  5. flashbytes says

    Is there a way to avoid multiple new js files? Wouldn’t it be possible to add this js (both files) to one that is already being loaded by default, so the page load doesn’t suffer as much as it would, if there were three files instead of one?

  6. Rob says

    Thanks!!!! adding the

    .post, .page

    into the CSS selector worked great for me and the pages I have videos on…I have yet to add a blog post but I’m sure it should work fine with that since it worked for me on my pages

    THANKS!!!!

  7. Michael Boll says

    Thanks for this great tip.

    Do you know of a plugin that will allow video to be seen on an ipad?

    We are a school using WOrdpress like crazy (self hosted) but when we upload video to our wordpress sites, it cannot be seen on an iPad.

    Looking for a plugin to fix this. Any suggestions?

    We can view all other videos on an iPad, just not ones hosted on our own wordpress server. Not sure why it does not render in HTML 5.

    Thanks,

    Mike

    • WPBeginner Support says

      Michael, We think users should never upload videos to WordPress. We think embedding videos from a source like YouTube or Vimeo are a better alternative. However, if you must upload video, then WordPress comes with the video shortcode since version 3.6. Your videos must be in iPad supported format like mp4, m4v, ogv, mov, etc. You can also use a program like WinFF to convert your videos into iPad supported format.

      Administrator

  8. Denis McCaul says

    I have since researched and found that adding
    .post, .page
    rather than just .post means it now works for me on Posts and Pages.
    Any solutions to the incompatability with Plugin „Lazy Load for Videos” greatly appreciated.
    Thanks, Denis

  9. Denis McCaul says

    I installed the plugin and followed your set up instructions, good news and bad.
    Good news, it works.
    Bad news
    1. It is not compatible with the Plugin „Lazy Load for Videos”. I had to deactivate that one for it to work. So page now takes longer to load especially if multiple videos.
    2. I added the .post CSS selector as advised in the settings. This makes it work on Blog posts but not on Video’s embedded on Pages. If you change .post to .page instead it will thenl work on pages but not posts.
    Any way to fix these problems?
    Thanks, Denis

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.