#103: Integrating FitVids.js into WordPress

Nov 2 2011

The default WordPress theme at the time of this screencast is TwentyEleven, a wonderfully simple and responsive design. That is, until we post an awesome YouTube video as a new blog post and the responsiveness breaks down. The video doesn't fill the area on wide screens and is too big on narrow screens, breaking outside the content area.

In this video we'll cover how to add jQuery to a WordPress theme, then download the jQuery plugin FitVids.js and integrate it into the theme (simple stuff!). The result is the video instantly fits the responsive nature of the theme. It works for video from any source.

Even though this is a simple and specific example, I hope it helps you understand how you can get started integrating any cool JavaScript thingy you find on the web into a WordPress site.

Links from the video:

Running Time: 20:58

Download Video File

Subscribe to The Thread

  1. First line: “I have prepared for this zero” – love it Chris

  2. Thanks for sharing. This is gonna help tons!

    I always learn (and laugh a bit) while watching your tutorials.

  3. Bert de Vries

    Very nice. Thank you.
    Did miss the ‘bye’ at the end though :)

  4. JJMeher

    Awesome this came just in time! I am going to merge this into this Bones theme I found and give it a test run. Thank you Jacob for letting me know how to get this loaded in the footer!

  5. You are my hero dude. Keep up the great work!

  6. I don’t even use wordpress. I just watch this for the entertainment and pure brilliance. :) moar videoz!

  7. Thank you so much, this is such a valuable tool, your video is also wonderful and entertaining! keep it up, I hope you enjoy much succes with any thing you do! keep rockin :D

  8. Chris,

    Thank you for your interesting tip & tutorial.
    Could this be combined with the Screencast.com wordpress plugin?
    https://wordpress.org/extend/plugins/screencastcom-video-embedder/

    Is there an improvement opportunity by combining both plugins into one new plugin? Does this give you any new ideas to test? If so, please post a new screencast on this topic.

    Thanks again!

  9. LOL! Great video and made me style. You are talented to get this stuff, figure it out and pass it on to other people.

    I am ASP/ASP.NET developer for YEARS and absolutely love WordPress and JQuery. Just getting into WP Plugin Integration.

    This video was helpful in knowing what to tweak and where to put files and get proper path references. You just made me a few hundred bucks this year.

    Thank you!

  10. *style = smile with your style.

  11. Works Great! Thank you.

    First time i have seen that WTFPL license.

  12. Is this now included in WP3.3? It appears to already resize in 3.3. Maybe I’m doing something wrong or just got lucky.

  13. Eric

    Thanks for the video. I’ve got fitvids.js installed and all scripts are loading as they should. The thing I’m trying to do differently is rather than put my Vimeo embed code into a post or a page, I’m hard coding it into index.php into a div where I want my video to live.

    Does anyone know how to accomplish this? What will I need to do differently? (Unfortunately I can’t provide an example link as the site has yet to launch.)

    Here’s what I’ve got so far:

    
    <script type="text/javascript" src="/js/jquery.fitvids.js"></script>
    <script>
      $(document).ready(function(){
        // Target your .container, .wrapper, .post, etc.
        $("#banner").fitVids();
      });
    </script>
    

    And in index.php:

    
    <div id="banner">
    			<iframe id="video" src="http://player.vimeo.com/video/XXXXXXXX?title=0&byline=0&portrait=0&color=EA1D25&autoplay=1&loop=1" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
    		</div>
    

    And for the CSS:

    
    #banner { min-width: 100%; height: auto; }
    iframe#video { min-width: 100%; height: auto; }
    

    Thanks!!!

    • Eric

      Well, despite having errors in my code above (iframe id=”video” amongst others I’m sure), the main problem is seems to be that fitvids.js was corrupt. I tested this by re-downloading the package on github, and then plugging in my remote jquery.fitvids.js path into the local tests.html file, and it stopped working. Dropped in a fresh fitvids.js copy remotely, and boom!

  14. There’s a Plugin for that! You don’t want to touch your theme files? Go and get Kevin Dees’ Plugin in the Extend at http://wordpress.org/extend/plugins/fitvids-for-wordpress/

  15. you made me laugh out loud with this post at least 3 times. thanks!

  16. Thanks for making me choke on my apple. Oh yeah, and the tutorial too.

  17. Jerry

    Hey Chris, how could you make a flash 360 panoramic file dynamic? And also an html5 panoramic?
    Would you also use the fitvid script?

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~