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

Como tornar seus vídeos responsivos no WordPress com o FitVids

Nota editorial: Ganhamos uma comissão de links de parceiros no WPBeginner. As comissões não afetam as opiniões ou avaliações de nossos editores. Saiba mais sobre Processo editorial.

Quando você incorpora um vídeo no WordPress, por padrão, esses vídeos não são responsivos. Com o aumento dos temas responsivos do WordPress, os usuários que visitam seu site em telas menores verão contêineres de vídeo esticados e desproporcionais. Neste artigo, mostraremos como tornar seus vídeos responsivos no WordPress com o FitVids.

Default non-responsive and responsive video embeds in WordPress

O FitVids é um plug-in jQuery que permite que você torne suas incorporações de vídeo responsivas. Se quiser usá-lo em seu site WordPress, tudo o que precisa fazer é instalar e ativar o plug-in FitVids para WordPress. Após a ativação, você precisa ir para Appearance ” FitVids e inserir uma classe de seletor CSS. O WordPress adiciona automaticamente a classe .post aos artigos, portanto, você pode simplesmente usá-la.

FitVids for WordPress plugin settings

Isso é tudo, salve suas alterações e visualize seu site. Você precisará redimensionar a tela do navegador para ver os vídeos se ajustando adequadamente.

Tutorial em vídeo

Subscribe to WPBeginner

Se você não gostar do vídeo ou precisar de mais instruções, continue lendo.

Adicionar manualmente o FitVids para tornar seus vídeos responsivos no WordPress

Se não quiser instalar o plug-in FitVids para WordPress, você pode adicionar o plug-in FitVids jQuery manualmente. A primeira coisa que você precisa fazer é baixar e extrair o plugin FitVids jQuery para o seu computador. Agora você precisa fazer o upload da pasta extraída FitVids.js-master para o diretório js do seu tema.

Você precisa se conectar ao seu site usando um cliente FTP como o Filezilla e abrir o diretório do tema. É possível que seu tema do WordPress não tenha uma pasta js. Se ela não estiver lá, você precisará criar uma e, em seguida, carregar a pasta FitVids.js-master do seu computador.

Dentro da pasta js, você precisa criar um novo arquivo e nomeá-lo FitVids.js. Edite esse arquivo e cole o código dentro dele.

(function($) {
  $(document).ready(function(){
    // Direcione seu .container, .wrapper, .post, etc.
    $(".post").fitVids();
  });
  
  })(jQuery);

O código acima diz ao FitVids para procurar a classe de seletor CSS .post. Agora que você tem o FitVids pronto, é hora de adicionar corretamente os javascripts em seu tema do WordPress.

Simplesmente, copie e cole o seguinte código no arquivo functions.php de seu tema:

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);

Depois de fazer isso, está tudo pronto. Você conseguiu tornar seus vídeos do WordPress responsivos.

Esperamos que este artigo tenha sido útil para você. Para comentários e perguntas, deixe um comentário abaixo ou junte-se a nós no Twitter e no Google+.

Divulgação: Nosso conteúdo é apoiado pelo leitor. Isso significa que, se você clicar em alguns de nossos links, poderemos receber uma comissão. Veja como o WPBeginner é financiado, por que isso é importante e como você pode nos apoiar. Aqui está nosso processo editorial.

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.

O kit de ferramentas definitivo WordPress

Obtenha acesso GRATUITO ao nosso kit de ferramentas - uma coleção de produtos e recursos relacionados ao WordPress que todo profissional deve ter!

Reader Interactions

16 ComentáriosDeixe uma resposta

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

      Administrador

  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

Deixe uma resposta

Obrigado por deixar um comentário. Lembre-se de que todos os comentários são moderados de acordo com nossos política de comentários, e seu endereço de e-mail NÃO será publicado. NÃO use palavras-chave no campo do nome. Vamos ter uma conversa pessoal e significativa.