Category: Featured

  • 15 going on to 16

    This is my last-ditch attempt to write a blog post in 2015. I thought it would be nice to look back on the year and make plans for the new year.

    In 2015

    • Attended WordCamp Paris
    • Promoted as an admin in the theme review team
    • Gave a talk on “Do’s and Don’ts of WordPress Theme Development” at the WordPress Meetup in Bern
    • Attended WordCamp Köln
    • Stopped working at CyberChimps after working there for two years
    • Missed WordCamp Europe 🙁
    • Failed my exams which I will be retaking in 2017
    • Was able to hand over the organising of the WordPress Meetups in Bern to a friend for the second half of the year as I was not able to attend the Meetups
    • Became a conscript. I have to serve until end of April 2016 🙁 Then I will be free for the rest of my life. 🙂
    • Helped organize WordCamp Switzerland
    • Worked on a new WordPress company that my friend Stefan and I are planning of launching in 2016
    • Contributed to TwentySixteen and WP 4.4 with a inline docs patch
    • Contributed to some WordPress related projects like _s and EDD
    • Released a new plugin Polylang Slug
    • Passed my theoretical driving test
    • Increased the amount I have earned from WordPress related work

    In 2016 I plan to do the following things

    • Launch the new WordPress theme and plugin site and a few products
    • Pass my driving test
    • Going to watch my first WWE live event with my brother in Glasgow
    • Get a part-time job related to WordPress. Need to start looking 🙂
    • Travelling to Paris from May to July to work on my French and take the French B2 exam
    • Attend WordCamp Europe in June
    • Visit Japan for a month and traiu and possibly a WordCamp if there is one
    • Attend WordCamp Lahore in September
    • Help organize WordCamp Switzerland again
    • Attend WordCamp US and the Contributor Summit
    • Improve in my JavaScript skills
    • Integrate accessibility testing in my workflow
    • Write a unit test

    That is about it. 🙂

  • Bundling plugin, libraries and frameworks in themes

    Securi released a post revealing that two popular WordPress plugins had a serious vulnerability.

    Theme plugin have been bundled into a number of themes. This caused a number of people to mention that one should not bundle plugins in WordPress themes.

    I agree with Rarst that there is no difference between bundling plugin, libraries or frameworks as they are both are just code. Eric wrote a few thoughts on “Dependency Management in WordPress“. WordPress is still not at the stage where dependency management can be implemented that the average user can use.

    A number of themes use setting frameworks. There was once a discussion on the WordPress.org Theme Review mailing list and it was decided that theme developers should ship the themes with the integrated setting frameworks instead of installing the plugin version of the framework using something like TGM. By including the frameworks in the theme the developer is making the decision for the user and not giving him/her further options. Users find it confusing to see plugins that they do not remember installing. The settings frameworks are not the only frameworks. There are others like the metabox frameworks or theme frameworks.

    One of my plugins is FluidVids for WordPress. The plugin makes it easier for people to use FluidVids from Todd. I regularly track updates and include them in the plugin. It the developers responsibility to track the updates of the libraries, frameworks or even plugins that they have bundled in their theme and update them as soon as there is an update.

  • WCCH14: How to Manage Translations

    Here are the slides from talk at WordCamp Switzerland 2014 on how to manage translations.

    Below is the video of my presentation.

  • Future of POT generators

    One of the first big problems that I faced when I started with WordPress was how to generate  a POT file. In the meantime have been able to look at all of the different tools and see their shortcoming with challenges that I faced when generating a POT file.

    Challenges with POT generation

    Recently I have been working on projects where the POT file generation needed to be different. Here are three examples:

    I was working on Responsive and Responsive Pro. Responsive is currently translated in about 45 languages. A large majority of the strings in Responsive Pro were already translated in Responsive. So to reduce the workload for the translators I created a separate POT for the pro folder which is only in the pro version.

    Another example from CyberChimps where we use a framework for all of our themes except for Responsive. The framework is the core folder and it is in every theme. If we created the POT files the standard way then we would have all of the same strings across all of our themes which would create extra work for the translators. We could use a constant and define that in the functions.php but it is not allowed in the current WordPress.org theme review guidelines. The core has it’s own text domain, pot file and translations.

    A third example that I came across is when using TGM Plugin Activation. TGM Plugin Activation has it’s own strings with it’s own text domain tgmpa. With the current POT generation solutions the strings will be added to the POT but the translations will not load as the text domain is never loaded. A solution could be to just to load your own version of the strings with your own strings. I know a number of plugins and themes use this library. TGM Plugin Activation should load it’s text domain and have it’s own language folder. We as a community can contribute to it and then themes and plugin are able to profit from the standard strings being fully translated.

    Shortcomings of current generators

    I also find makepot.php is too narrow minded to use as it expects that the folder name is the same as text domain. There are multiple times where it is not so in developement. I develop the Flowplayer HTML5 WordPress plugin and the GitHub repo is named wordpress-flowplayer as it make sense to separate it from the Flowplayer player GitHub repo which is part of the same GitHub organisation. So when I use makepot it thinks the text domain is wordpress-flowplayer instead of flowplayer5 which is the WordPress.org plugin slug. Another case would be if when developing a plugin in the same WordPress.org svn structure. The main plugin is most times in the trunk folder and makepot.php would then think that the theme slug should be trunk.

    Poedit Pro handles text domains great. It check for the header info Text Domain and uses that to define the text domain. It currently supports the WordPress translators comments but the not the plugin or theme meta data yet. This is still a very manual process of creating the POT. It also uses the folder structure to choose the files where the strings are pulled from.

    Both makepot.php and Poedit use the location of the files when choosing which strings to add to the POT but neither solution can yet exclude folders.

    In November 2013 Stephen Harris released a new solution grunt-pot. I was really pleased with this solution as it includes an option to define the files that you want and do not want to scan. The thing that is missing is that it does not support fetching WordPress meta data and translator comments.

    Future POT generator

    The perfect POT generator  for me would be one that used the text domain to choose which strings get added to POT file. The solution would need to able to define the location of the files, text domain, and the location of the language folder. For WordPress it would be very important that the translator comments and plugin/theme meta data are also included in the POT. The solution should be built using grunt as it works with every OS can be easily integrated in a build workflow.

  • Complete Breakdown of Responsive Videos

    I have been asked a few times about adding responsive videos. At the time I was unable to give a good answer. Now I have taken time to do a bit of research and I able to give a number of responsive video solutions. The solutions are divided in third party services or self hosted solutions. Some of the solutions have WordPress plugins, these are marked with “WP Plugin”. Here are the solutions and resources I am going to cover.

    Update on 8th December 2013
    I wrote this post on ThemeID which has now been bought by CyberChimps. I have now updated the post with info to some WordPress plugin and small improvements and now have it on my blog.

    Cloud hosted videos

    These video solutions are most times the simplest. They host the video for you and work on most devices. So that they are responsive you need to use some tricks when embedding them. There are even some WordPress plugins that help. Responsive Video Embeds and Advanced Responsive Video Embedder are such plugins.

    YouTube

    • Very easy to set up
    • Needs a iframe solution so that it is responsive
    • The video is hosted on YouTube
    • Works easily on multiple devices and browsers
    • YouTube has some developer customisation options

    The easiest solution is to use YouTube. It works on multiple devices. In some countries YouTube plays an advertisement before the video. If  you upload your own video this should not be the case. At the end of the video you get a grid with other videos. If you don’t want those then when embedding YouTube make sure you uncheck the “Show suggested videos when the video finishes”.

    YouTube share settings
    YouTube share settings

    YouTube has some advanced customisation options. You can test them out on the demo page.

    YouTube Demo

    Vimeo

    • Very easy to set up
    • Needs a iframe solution so that it is responsive
    • The video is hosted on Vimeo
    • Works easily on multiple devices and browsers
    • Paying users can customise the player

    Vimeo has a lot of the same features as YouTube but it has paid plans which give users more options for customisation.

    vimeo-share

    Vimeo Demo

    Wistia

    • Very Simple – only one file to upload
    • The code is an iframe
    • Hosted on the Wistia servers
    • Built in Video analytics
    • Free version (3 videos / 5 GB bandwidth / branded player)
    • Paid version begins at $25/mo
    • Has additional features e.g. social sharing, call to action, require email to play and a few more which you can find here.

    Wistia Embed & Share
    Wistia Embed & Share

    Solution 1

    <iframe src=”http://fast.wistia.net/embed/iframe/3bfl0abrog?controlsVisibleOnLoad=true&version=v1&videoHeight=360&videoWidth=640&volumeControl=true” allowtransparency=”true” frameborder=”0″ scrolling=”no” class=”wistia_embed” name=”wistia_embed” width=”640″ height=”360″></iframe>

    Wistia Demo

    Solution 2

    There is a solution where Wistia supports responsive videos with their own code so a JavaScript plugin is not needed. There are three ways of doing this.

    The first two are documented on the Wistia DemoBin. There is the Video Foam Lab page where you can paste the embed code to make it responsive.

    1. If you have an iframe, load the iframe API script in the footer and add `&videoFoam=true` at the end of the url in the iframe. e.g.  
      <iframe src=”http://fast.wistia.net/embed/iframe/3bfl0abrog?videoFoam=true” allowtransparency=”true” frameborder=”0″ scrolling=”no” class=”wistia_embed” name=”wistia_embed” width=”640″ height=”360″></iframe>
      <script src=’//fast.wistia.com/static/iframe-api-v1.js’></script>
    2. If you have an API or SEO embed, just pass `videoFoam: true` in with your embed parameters, e.g. 
      <div id=”wistia_3bfl0abrog” class=”wistia_embed” style=”width:640px;height:360px;”> </div>
      <script charset=”ISO-8859-1″ src=”http://fast.wistia.com/assets/external/E-v1.js”></script>
      <script>
      wistiaEmbed = Wistia.embed(“3bfl0abrog”, {
      videoFoam: true
      });
      </script>
    3. To make all Wistia videos responsive on your site add this code to the header.
      <script src=”//fast.wistia.com/static/embed_shepherd-v1.js”></script>
      <script>
      wistiaEmbeds.onFind(function(video) {
      video.videoFoam(true);
      });
      </script>

    The Wistia WordPress plugin enables oEmbed. This allows you to just insert the special url and then the plugin does the rest so that you see a video on the front end. So that the video is responsive, add &amp;videoFoam=true at the end of the url. e.g. http://grappler-login.wistia.com/medias/3bfl0abrog?embedType=iframe&amp;videoWidth=640&amp;videoFoam=true

    Wistia’s own demo My Wistia demo

    Self Hosted Videos

    These solutions are for those people who want to host their own videos be it on their own server, uploading it through WordPress or hosting it in the cloud like with Amazon S3.

    Simple HTML5 Video

    • Need to create markup
    • Simple setup
    • Videos hosted on own site
    • Different players on every browser
    • IE 8 and lower are not supported

    The video tag is a new standard to display videos. I have added more information then you might need. To understand it best I have split this section into two parts.

    HTML5 Markup

    Here is a simple code example

    <video src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” width=”320″ height=”240″ controls=”controls” preload=”none”></video>

    So that the videos will work on multiple browser we will need multiple formats.

    Here is a simple code example. I have also added a possibility to load a lower resolution video for smaller devices.

    <video width=”320″ height=”240″ controls preload=”metadata”>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” type=”video/webm”>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″ type=”video/mp4″>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv” type=”video/ogg”>
    </video>

    HTML5 multiple format Demo

    The video Tag has the following attributes. Some of them are easy to understand.

    • global attributes – standard attributes like class and id
    • autoplay
    • preload – none, metadata, auto
    • controls
    • loop
    • poster – poster=”/image.jpg”
    • height
    • width
    • mediagroup – control two media elements(videos) through the first element(video)
    • muted
    • src – video link

    W3 Video Tag Reference

    Here are the source attributes.

    • global attributes
    • src
    • type
    • media

    W3 Source Tag Reference

    So to have a responsive HTML5 video you need to have this CSS.

    video {
    width: 100%;
    max-width: 100%;
    height: auto;
    }

    You can use a service provided by video.js to create HTML5 video markup.

    You can read up more on the video files below.

    Simple HTML5 Video with flash fallback

    • The same points as for HTML video except with IE8 and lower support

    This is how the code would look like with Flowplayer being used as the backup.

    <!– “Video For Everybody” http://camendesign.com/code/video_for_everybody –>
    <video controls=”controls” poster=”http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg” width=”960″ height=”540″>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″ type=”video/mp4″ />
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” type=”video/webm” />
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv” type=”video/ogg” />
    <object type=”application/x-shockwave-flash” data=”http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf” width=”960″ height=”540″>
    <param name=”movie” value=”http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf” />
    <param name=”allowFullScreen” value=”true” />
    <param name=”wmode” value=”transparent” />
    <param name=”flashVars” value=”config={‘playlist’:[‘http%3A%2F%2Ftesting.grappler.tk%2Ffiles%2F2013%2F01%2Ftrailer_1080p.jpg’,{‘url’:’http%3A%2F%2Ftesting.grappler.tk%2Ffiles%2F2013%2F01%2Ftrailer_1080p.mp4′,’autoPlay’:false}]}” />
    <img alt=”Big Buck Bunny” src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg” width=”960″ height=”540″ title=”No video playback capabilities, please download the video below” />
    </object>
    </video>
    <p>
    <strong>Download video:</strong> <a href=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″>MP4 format</a> | <a href=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv”>Ogg format</a> | <a href=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm”>WebM format</a>
    </p>

    To save time you could use the Video for Everybody generator by Jonathan Neal to generate the code snippet according to your options. (FlashFox player seems to only resize if the browser is refreshed but does not change size dynamically,)

    A complete explanation can be found at Kroc Camen’s site, the originator of this technique.

    HTML5 with flash fallback Demo

    Sublime Video

    • Easy to set up with the code generator
    • Need to add JavaScript code
    • No need for JavaScript plugins
    • Basic HTML5 code with flash fallback for IE8
    • Works with self hosted videos and YouTube videos

    Sublime offers a solution for your own hosted videos and YouTube videos. Chose your option and then add the link to your media or for the YouTube videos add the video id.

    Sublime Video Source
    Sublime Video Source

    In the video setting the “Fit” option is very important.

    Video Settings
    Video Settings

    At the end you can click on the “Get the Code” button at the bottom. You will then get a code like this.

    <video id=”a240e92d” class=”sublime” poster=”https://cdn.sublimevideo.net/vpa/ms_800.jpg” width=”640″ height=”360″ title=”Midnight Sun” data-uid=”a240e92d” data-autoresize=”fit” preload=”none”>
    <source src=”https://cdn.sublimevideo.net/vpa/ms_360p.mp4″ />
    <source src=”https://cdn.sublimevideo.net/vpa/ms_720p.mp4″ data-quality=”hd” />
    <source src=”https://cdn.sublimevideo.net/vpa/ms_360p.webm” />
    <source src=”https://cdn.sublimevideo.net/vpa/ms_720p.webm” data-quality=”hd” />
    </video>

    The next step is to add the loader code. This add the Java Script. Every site has its own file.

    <script type=”text/javascript” src=”//cdn.sublimevideo.net/js/emx0sm0y.js”></script>

    Sublime Demo (YouTube video) Sublime Demo (hosted video)

    Flowplayer

    • No need of JavaScript Plugin
    • Easy to use
    • Customisable players
    • WordPress plugin with video manager
    • Multiple customisation options

    Simply add this HTML to page or post.

    <link rel=”stylesheet” href=”//releases.flowplayer.org/5.4.4/skin/minimalist.css”>
    <script src=”http://releases.flowplayer.org/5.4.4/flowplayer.min.js”></script>
    <div class=”flowplayer play-button” data-ratio=”0.5625″>
    <video controls=”controls” preload=”metadata” data-embed=”false”>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″ type=”video/mp4″></source>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” type=”video/webm”/></source>
    <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv” type=”video/ogg”/></source>
    </video>
    </div>
    view raw flowplayer.html hosted with ❤ by GitHub

    Flowplayer Demo

    Design your own playerVideo attributesAdditional options

    Flowplayer WordPress plugin

    It is really simple to use. You upload the video files and then you add the different file formats and choose a skin and define settings. For every video you get a shortcode that you can paste in a post or page.

    Flowplayer5 for WordPress
    Flowplayer5 for WordPress

    Flowplayer5 for WordPress Demo Flowplayer5 for WordPress

    Note! I am developing the Flowplayer WordPress plugin.

    MediaElement.js

    • Standard Player
    • Out of the box responsive
    • Supports HTML5 Video
    • Automatically supports IE8 and lower
    • WordPress plugin Now part of WordPress Core
    • Does not need a JavaScript plugin

    How to get it running on your site.

    1. First you need to download the files.
    2. Open the zip file and then extract the build folder
    3. Move that build folder to your child theme. You can rename the folder if you want
    4. Load mediaelement-and-player.min.js and mediaelementplayer.min.css
    5. Load this javascript to activate the MediaElements player
      // activate mediaelementplayer
      jQuery(‘video,audio’).mediaelementplayer(/* Options */);
    6. Then you can include the HTML video code.
      <video width=”320″ height=”240″ controls preload=”metadata”>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” type=”video/webm”>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″ type=”video/mp4″>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv” type=”video/ogg”>
      </video>

    MediaElement Demo

    MediaElement.js WordPress plugin

    This is very simple. Install the plugin and then add this shortcode to the post or page. Just change the links to your video.

    [video
    poster="http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg"
    mp4="http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4"
    webm="http://testing.grappler.tk/files/2013/01/trailer_1080p.webm"
    ogg="http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv"
    width="100%"
    height="100%"
    ]

    MediaElement WordPress Plugin Demo

    Video.js

    • Flash Fallback
    • WordPress Plugin
    • Needs FitVids.js
    1. Load the JavaScript and Stylesheet
    2. Add the markup e.g.
      <link href=”http://vjs.zencdn.net/c/video-js.css” rel=”stylesheet”>
      <script src=”http://vjs.zencdn.net/c/video.js”></script>
      <div class=”video-js-wrapper”>
      <video id=”video-js-1″ class=”video-js vjs-default-skin” controls width=”960″ height=”540″ poster=”http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg” preload=”auto” data-setup=”{}”>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4″ type=”video/mp4″></source>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm” type=”video/webm”/></source>
      <source src=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv” type=”video/ogg”/></source>
      </video>
      </div>
      view raw video.js.html hosted with ❤ by GitHub
    3. Add extra css
      .fluid-width-video-wrapper .video-js {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%!important;
      height: 100%!important;
      }
      view raw video.js.css hosted with ❤ by GitHub
    4. Activate FitVids.js for Video.js
      // FitVids
      jQuery(document).ready(function(){
      // Target your #container, #wrapper etc.
      jQuery(“#wrapper”).fitVids({ customSelector: “div[class^=’video-js-wrapper’]”});
      });

    Video.js Demo

    Options Documentation

    Video.js WordPress plugin

    The plugin does make it a bit easier to host the files. Install and activate the plugin. On a page you will find a button to open a form to create the shortcode.

    Add Video Button
    Add Video Button

    Video.js WordPress Plugin
    Video.js Shortcode Form

    This is the code that this form will generate.

    <div class=”video-js-wrapper” width=”960″ height=”540″>
    [video
    poster=”http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg”
    mp4=”http://testing.grappler.tk/files/2013/01/trailer_1080p.m4v”
    webm=”http://testing.grappler.tk/files/2013/01/trailer_1080p.webm”
    ogg=”http://testing.grappler.tk/files/2013/01/trailer_1080p.ogv”
    width=”960″
    height=”540″
    ]
    </div>

    Videos.js WordPress Plugin Demo Video.js WordPress Plugin

    JW Player

    • Popular
    • Only from Version 6 responsive out of the box
    • Extra work for every video

    JW Player 6

    As of JW Player 6 responsive videos are supported. JW Player has a guide on how to enable responsive videos.

    The following snippet is an example.

    <script src=”//cdn.jsdelivr.net/jwplayer/6.7/jwplayer.js”></script>
    <div id=”player_6″></div>
    <script>
    jwplayer(“player_6”).setup({
    image: “http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg”,
    file: “http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4”,
    width: “100%”,
    aspectratio: “16:9”
    });
    </script>

    JW Player 6 Demo

    JW Player 5

    For JW Player 5 you will need to use some hacks. Below are a few of options.

    Standard embed with responsive CSS Solution

    I have found another way of making JWPlayer responsive. This should be a bit easier.

    1. Add this code to the page or post
      <script type=”text/javascript” src=”//cdn.jsdelivr.net/jwplayer/5.10/jwplayer.js”></script>
      <div id=”player_1″></div>
      <script type=”text/javascript”>// <![CDATA[
      jwplayer(‘player_1’).setup({
      file: “http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4”,
      width: “100%”,
      height: “100%”,
      stretching: “fill”,
      flashplayer:”//cdn.jsdelivr.net/jwplayer/5.10/player.swf”
      });
      // ]]></script>
    2. Change the div id so that is different for every video. Make sure it matches the code in the JavaScript.
    3. Add this css
      #player_1_wrapper {
      width: 100%;
      position: relative;
      padding: 0;
      padding-bottom: 56.25%;
      }
      #player_1_wrapper object {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      }
      view raw JWPlayer.css hosted with ❤ by GitHub

      You will need to add this css for every video.
    4. So that the video keeps its proportion you will need to change the padding-bottom percentage. This is calculated video height / width x 100. E.g. 540 / 960 x 100 = 56.25%.

    JW Player 5 wo/ iframe Demo

    iframe Solution

    The solution that I have for JW Player is a hack that Ethan from Longtailvideo sent me. Here is how to do it.

    1. Download the files
    2. Copy jwplayer folder to your child theme using a ftp client
    3. Create a html file in the child theme
    4. Paste this code in
      <!DOCTYPE HTML>
      <html>
      <head>
      <title>
      JW Player Reponsive Video
      </title>
      <script type=”text/javascript” src=”//cdn.jsdelivr.net/jwplayer/5.10/jwplayer.js”>
      </script>
      <style type=”text/css”>
      html, body {
      height: 100%;
      width: 100%;
      padding: 0;
      margin: 0;
      }
      #player {
      height: 100%;
      width: 100%;
      padding: 0;
      }
      </style>
      </head>
      <body>
      <div id=”player”>
      </div>
      <script type=”text/javascript”>
      jwplayer(“player”).setup({
      file: “http://testing.grappler.tk/files/2013/01/trailer_1080p.mp4”,
      image: “http://testing.grappler.tk/files/2013/01/trailer_1080p.jpg”,
      height: “100%”,
      width: “100%”,
      stretching: “exactfit”,
      flashplayer:”//cdn.jsdelivr.net/jwplayer/5.10/player.swf”
      });
      </script>
      </body>
      </html>
    5. Change four links – Change the location of jwplayer.js, jwplayer.flash.swf, the video link and either update the image link or remove it.
    6. Then add an iframe with the link pointing to the newly created html file.
      <iframe width=”940px” height=”540px” src=”http://grappler.tk/wp-content/themes/responsive-testing/jwplayer-iframe.html” frameborder=”0″ allowfullscreen=””></iframe>
    7. Then we have to make sure that FitVids.js will work with this iframe. More on this here.

    JW Player 5 iframe Demo

    JW Player Documentation

    JW Player WordPress Plugin

    The WordPress plugin supports both JW Player 5 and 6. You can switch between the two. You need JW Player 6 for responsive support. You define the ratio per player.

    Add video to JW Player

    JW Player WordPress Plugin Demo JW Player WordPress Plugin

    Additional Information

    Here are a few things that you might need to know when working with responsive videos.

    Video Files and Formats

    There are three main video files.

    Format Video Encoding MIME-type
    MP4 H264 video/mp4
    WebM VP8 video/webm
    Ogg Theora video/ogg

    Not every browser supports all formats that is why we include all of them in the html.

    Flowplayer,  SublimeVideo and JW Player have documentation on encoding, video formats and sizes.

    If you have a MP4 file you can use firefogg.org (a firefox extension). It is very simple to use but if you need help you can follow this guide.

    You can also use an online service like encoding.com, Amazon Elastic Transcoder (beta) or Zencoder.

    The easiest way to get your video in the different formats on your computer is to use Miro converter. It is very simple to use but if you need help you can follow this guide.

    Heads up! I had some problems playing the webm format in Firefox that was converted by Miro.

    Miro Support said:

    To get around this  download an updated version of ffmpeg from here: http://ffmpeg.zeranoe.com/builds/

    Take the ffmpeg.exe file from the updated build – and dropped it into C:Program FilesParticipatory Culture FoundationMiro Video Converterffmpeg –  replacing the existing ffmpeg.exe file and then convert without issue using MVC.

    We will have to make a new release to update ffmpeg – but in the meantime you can use the workaround and you should be all set.

    • Mozilla Firefox – WebM, Ogg
    • Google Chrome – MP4, WebM, Ogg
    • Opera – WebM, Ogg
    • Safari – MP4
    • Internet Explorer 9+ – MP4
    • Internet Explorer 6-8 – No HTML5, Flash Only!

    To test it your self

    Video Format Test HTML5 multiple format Demo

    Further reading.

    WordPress does not support webm at the moment and for that reason you will need to add the following code to your themes functions.php. If you are running a multisite you will need to check the list of allowed files.

    <?php
    function support_custom_mimes( $mimes ){
    $mimes[‘webm’] = ‘video/webm’;
    return $mimes;
    }
    add_filter( ‘upload_mimes’, ‘support_custom_mimes’ );

    Solutions for iframe embeds

    Embed Responsively

    This solution is useful if you only have one or a few videos on your site and you are able to make the iframe responsive.

    embedresponsively.com
    embedresponsively.com

    This then outputs html code like this.

    <style>
    .embed-container {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 30px;
    height: 0;
    overflow: hidden;
    max-width: 100%;
    height: auto;
    }
    .embed-container iframe, .embed-container object, .embed-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    }
    </style>
    <div class=’embed-container’>
    <iframe src=’http://www.youtube.com/embed/jKQz6A8Mi3E’ frameborder=’0′ allowfullscreen></iframe>
    </div>


    So that the video doesn’t distort  and has the correct aspect ratio the JavaScript calculates the aspect ration. This is calculated by dividing the height by the width in the html code. That is why it is important the width and height is correct.

    FluidVids.js

    FluidVids.js is a standalone JavaScript for fluid YouTube/Vimeo iframe embeds. You can easily add more custom/responsive players easily with the options script.

    FluidVids for WordPress demo FluidVids for WordPress

    FitVids.js

    FitVids.js is a lightweight, easy-to-use jQuery plugin for fluid width video embeds. FitVids.js makes iframe embed responsive on the fly. There is a WordPress plugin FitVids for WordPress.

    Here are a couple of important things to know about FitVids.js.

    The current version of FitVids.js conflicts with Video.js and MediaElement.js. That is why I would recommend using my version. It can be found on GitHub.

    When adding iframes from other sources then it is necessary to add selectors. So that I can add an iframe from this site I would use this JavaScript. It is also important to check if www is used or not.

    jQuery(document).ready(function(){
    // Target your #container, #wrapper etc.
    jQuery(“#wrapper”).fitVids({ customSelector: “iframe[src^=’http://grappler.tk’]”});
    jQuery(“#wrapper”).fitVids({ customSelector: “iframe[src^=’http://www.grappler.tk’]”});
    jQuery(“#wrapper”).fitVids({ customSelector: “iframe[src^=’http://fast.wistia.net’]”});
    });

    FitVids for WordPress

    Troubleshooting

    Here are two links to help with troubleshooting the video setup

    Multimedia Troubleshootinglongtailvideo.com

    Note! Please let me know if you would like me add another player. It might take some time. Please let me know if I should include any points that are important(Pro, Cons, Info) to the different players.
  • How to load theme and plugin translations

    You may ask yourself what is so special about this post. Does not the codex cover load_plugin_textdomain() and load_theme_textdomain() but this posts will show what else you can do with it.

    With this code for the theme and plugin you can add the translations in different places. The two reasons for this are:

    1. This allows for the translation to be placed in multiple places when the theme/plugin author does not add the translations to the theme/plugin and not have them deleted in every update.
    2. This also allows for the translations to be edited without needing to maintain the whole translation. For example there might be only one string that needs to be different for a site and so can be added to language directory before the theme/plugin language directory.

    How do .mo files work?

    So with the translation in the mo files if two of the same translations are loaded only the first translation will be displayed. So that is why in these code examples the plugin/theme language folders are loaded last. With if you only need to change a single string you would only need to add a single translation string in the directory that is loaded before.

    For the theme there are three different places; the WordPress language directory, the child theme language directory and the parent theme language directory.

    <?php
    function theme_name_setup(){
    $domain = ‘theme-name’;
    // wp-content/languages/theme-name/de_DE.mo
    load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain );
    // wp-content/themes/child-theme-name/languages/de_DE.mo
    load_theme_textdomain( $domain, get_stylesheet_directory() . ‘/languages’ );
    // wp-content/themes/theme-name/languages/de_DE.mo
    load_theme_textdomain( $domain, get_template_directory() . ‘/languages’ );
    }
    add_action( ‘after_setup_theme’, ‘theme_name_setup’ );
    view raw functions.php hosted with ❤ by GitHub

    For the plugin there are two different places; the WordPress language directory and the plugin language directory.

    <?php
    function plugin_name_load_plugin_textdomain() {
    $domain = ‘plugin-name’;
    $locale = apply_filters( ‘plugin_locale’, get_locale(), $domain );
    // wp-content/languages/plugin-name/plugin-name-de_DE.mo
    load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . ‘/’ . $domain . ‘-‘ . $locale . ‘.mo’ );
    // wp-content/plugins/plugin-name/languages/plugin-name-de_DE.mo
    load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . ‘/languages/’ );
    }
    add_action( ‘init’, ‘plugin_name_load_plugin_textdomain’ );
    view raw plugin-name.php hosted with ❤ by GitHub

    WordPress language directory

    The WordPress language directory can be found in wp-content. The code that we used would mean we would need a plugin or theme directory in the language directory for the translations.
    wp-content
    – languages
    – – plugin-name
    – – – plugin-name-de_DE.po
    – – – plugin-name-de_DE.mo
    – – theme-name
    – – – theme-name-de_DE.po
    – – – theme-name-de_DE.mo

    WordPress 3.7

    With the changes in WordPress 3.7 it will add support for automatically installing the right language files and keeping them up to date. These translations will be stored in the WordPress language directory under one directory for themes and another for plugins. The standard directory structure will look like this.
    wp-content
    – languages
    – – plugins
    – – – plugin-name-de_DE.po
    – – – plugin-name-de_DE.mo
    – – themes
    – – – theme-name-de_DE.po
    – – – theme-name-de_DE.mo

    You might ask yourself how this code will work with WordPress 3.7. What ever you are doing in now to load the text domain will work fine in WordPress 3.7. As the code uses the WordPress language directory but not the themes or plugins directory in the WordPress language directory all will be fine.

    WordPress checks if there are translation is in plugin/theme and if not then it will load the translation from WordPress language directory. If the translation are in the custom location in the WordPress language directory then the translations will be merged but the translations from the custom location will used unless not defined.

    In the future plugin and themes on WordPress.org repository will be able to update translations separately to the plugin or theme updates(This will launched separately to WordPress 3.7).

    Otto has a great post on this that must be checked out.

    Here is how you could conditionally load only one translation file and all of them one after each other.

    <?php
    function theme_name_setup(){
    $domain = ‘theme-name’;
    if ( $loaded = load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain ) ) {
    return $loaded;
    } elseif ( $loaded = load_theme_textdomain( $domain, get_stylesheet_directory() . ‘/languages’ ) {
    return $loaded;
    } else {
    load_theme_textdomain( $domain, get_template_directory() . ‘/languages’ );
    }
    }
    add_action( ‘after_setup_theme’, ‘theme_name_setup’ );
    view raw functions.php hosted with ❤ by GitHub
    <?php
    function plugin_name_load_plugin_textdomain() {
    $domain = ‘plugin-name’;
    $locale = apply_filters( ‘plugin_locale’, get_locale(), $domain );
    if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . ‘/’ . $domain . ‘-‘ . $locale . ‘.mo’ ) ) {
    return $loaded;
    } else {
    load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . ‘/languages/’ );
    }
    }
    add_action( ‘init’, ‘plugin_name_load_plugin_textdomain’ );
    view raw plugin-name.php hosted with ❤ by GitHub

  • Child themes, IE8 and Media Queries

    In my previous post I mentioned that one of the issues of using @import in the child theme is that the JavaScripts that help media queries in IE8 and lower so not work.

    So there  are three solutions.

    When using @import copy the media queries from the parent theme and paste in the child theme stylesheet.

    Pro

    • Simple and easy to do

    Con

    • For the rest of the browsers you have the media queries twice which makes debugging complicated
    • The media queries needs to be updated if there are any changes in the parent theme

    Use the solution of using functions.php that I presented in my previous post.

    Pro

    • Improves the loading speed of the stylesheets
    • The media queries are only in one place and thus do not need to be updated

    Con

    • This is a bit more complicated and perhaps not so easy to understand for beginners

    Theme authors add the media queries in a separate file and have the file always loaded from the parent theme

    Pro

    • The user is not confronted by this issue

    Con

    • An extra file is load just for the media queries
  • Improved way of loading parent styles in child themes

    The prefered method in the codex and with plugins that generate child theme is to load the parent stylesheet by using @import in the child themes stylesheet.

    @import url("../twentytwelve/style.css");

    There are a few problems with this.

    Speed

    Using CSS @import in an external stylesheet can add additional delays during the loading of a web page.

    Media Query support in IE

    Media Queries are not supported in IE8 or lower. So to support media queries on IE 8 and lower JavaScript is using like css3-mediaqueries-js and respond.js.

    Note: Doesn’t work on @import’ed stylesheets (which you shouldn’t use anyway for performance reasons). Also won’t listen to the media attribute of the <link> and <style> elements.

     

    @import rules are not supported by respond.js

    A solution to this could be to copy the media queries from the parent theme and include them in the child theme but this does not make it easy when there are changes in the media queries.

    More Flexibility

    This is not really a huge thing but it does make it easier to disable loading the parent stylesheet.

    Solution

    Now for the solution. Instead of using @import just add this PHP code to the functions.php of your Child Theme. If you don’t have one, simply create new file and name it functions.php

    Here is a variation that add the current parent theme version to the stylesheet url.

    There might be in some themes where the child theme stylesheet will load before parent theme style sheet. Those themes will have the code like this in the header

    For those cases add this PHP code to the functions.php in the child theme.

    In the perfect world the parent themes would load the stylesheet like _s does.

  • Responsive Opt-Out plugin

    Responsive Opt-Out allows visitors of your site to switch between the flexible and fixed width layout.

    This simple setup creates a body class called “responsive” and “fixed-width” both are added to the body class of your Theme. These two classes are used to define whether or not visitor wants a “responsive” environment.

    Here is a demo site that I have created using Responsive:

    Demo

    This the code you use for the switch buttons.

    <a href="#" onclick="return FixedWidth();" class="fixed-width-link">Fixed Width</a>
    <a href="#" onclick="return Responsive()" class="responsive-link">Reponsive</a>

    This CSS would display the right button in the right view.

    .responsive .fixed-width-link {
    	display: block!important;
    }
    .responsive .responsive-link {
    	display: none!important;
    }
    .fixed-width .fixed-width-link {
    	display: none!important;
    }
    .fixed-width .responsive-link {
    	display: block!important;
    }

    Here I was working in a child theme so was unable to edit the parent media queries but was still able to get a good result resting the css in the media queries.

    The basic fixed width CSS needed for Responsive would be:

    /* =Fixed Width
    -------------------------------------------------------- */
    .fixed-width #container,
    .fixed-width #footer {
    	width: 960px!important;
    }
    
    .fixed-width .grid, 
    .fixed-width .grid-right,
    .fixed-width .menu ul, 
    .fixed-width .menu li, 
    .fixed-width .footer-menu li, 
    .fixed-width .sub-header-menu li {
    	float: left!important;
    }
    
    .fixed-width .top-menu {
    	float: right!important;
    }
    
    .fixed-width #logo {
    	float: left!important;
    }
    
    .fixed-width .tinynav {
    	display: none!important;
    }
    
    .fixed-width .sb-holder {
    	display: none!important;
    }
    
    .fixed-width .menu {
    	display: block!important;
    }
    
    .fixed-width #featured p {
    	font-size: 18px!important;
    	line-height: 27px!important;
    }
    
    .fixed-width .featured-title {
    	font-size: 60px!important;
    }
    
    .fixed-width .featured-subtitle {
    	font-size: 2.25em!important;
    }
    
    .fixed-width .call-to-action a.button {
    	font-size: 24px!important;
    	padding: 15px 35px!important;
    }
    
    .top-widget {
    	float: right!important;
    }
    
    .fixed-width .top-widget area,
    .fixed-width .top-widget select,
    .fixed-width .top-widget textarea,
    .fixed-width .top-widget input[type="text"], 
    .fixed-width .top-widget input[type="password"] {
    	width: auto!important;
    }
    
    .fixed-width .widget-title,
    .fixed-width .widget-title-home h3 {
    	font-size: 24px!important;
    	height: 23px!important;
    	line-height: 23px!important;
    	text-align: left!important;
    }
    
    .fixed-width .main-nav #responsive_current_menu_item {
    	display: none!important;
    }
    
    .fixed-width .main-nav .menu {
    	top: 0;
    }
    
    .fixed-width .main-nav .menu a {
    	font-weight: 700!important;
    }
    
    .fixed-width .main-nav .menu li a {
    	color: #fff;
    	border: none;
    }
    
    .fixed-width .main-nav .menu li.current_page_item,
    .fixed-width .menu .current_page_item a,
    .fixed-width .menu .current-menu-item a,
    .fixed-width .main-nav .menu li {
    	background-color: transparent;
    }
    
    .js .fixed-width .main-nav .menu li a:hover,
    .js .fixed-width .main-nav .menu li li a:hover {
    	background-color: #808080;
    	background-image: -webkit-gradient(linear,left top,left bottom,from(#808080),to(#363636));
    	background-image: -webkit-linear-gradient(top,#808080,#363636);
    	background-image: -moz-linear-gradient(top,#808080,#363636);
    	background-image: -ms-linear-gradient(top,#808080,#363636);
    	background-image: -o-linear-gradient(top,#808080,#363636);
    	background-image: linear-gradient(top,#808080,#363636);
    	color: #fff;
    	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#808080,endColorstr=#363636);
    }

    Download

    You can also find the plugin on github.

    Extra

    I would be interested to see how many visitor use the button. You can track the number of click of the buttons with the use of Google analytic events. The results can be viewed in the Google Analytic dashboard. The html for these buttons will look like this.

    <a href="#" onclick="_gaq.push(['_trackEvent', 'Click', 'Responsive Opt-Out', 'Fixed Width']); return FixedWidth();" class="fixed-width-link">Fixed Width</a>
    
    <a href="#" onclick="_gaq.push(['_trackEvent', 'Click', 'Responsive Opt-Out', 'Responsive']); return Responsive()" class="responsive-link">Reponsive</a>

    Thank you Andrew for supporting this plugin.