Customizing WordPress Jetpack Mobile Theme

JetPack by WordPressI have successfully using Jetpack Mobile Theme to serve the mobile version of my blogs, as of now it uses a theme called minieleven (that is starting to look a bit old…), with some tweaks here and there it can shine brighter and be customized to your taste, but unfortunately you can’t use a child theme, so other strategies must be used, so all the hard work isn’t wiped out by an update (and you do your updates, right?).

The plug-in native customization options are rather weak. You can customize, excerpts or full posts in home/archive/search pages, hide or show featured images, and display a promo for WordPress mobile apps. And that’s it, no more customization options for the mobile theme. Actually (never tried myself) if your main theme has colour and background options they should be picked up. And that’s it. From that point onward it’s up to you. So here we go…

First, if you are using Adsense for monetization, you will probably will notice that the Adsense mobile ads come with a nasty yellow background and cropped at the far right. The fix is very easy, go to Jetpack-> Options -> Custom CSS (be sure to check Mobile-compatible to Yes and simply add this:

.mobile-theme ins.adsbygoogle {
	background-color: transparent !important;
}

.mobile-theme ins.adsbygoogle iframe {
	width: inherit !important;
}

This is an important concept, as from here you can CSS override anything in the mobile theme, just be sure to prefix your selector with the .mobile-theme class, so you don’t mess up the desktop version.

This is all good for minor adjustments, and let’s say honestly this Jetpack feature is a little bit dumb, because it adds the custom CSS both to the mobile and the desktop version, actually to act on mobile you must switch an option and append the .mobile selector. This is dumb because to customize a desktop theme you simply create a child theme…. let’s say you want to use your own font with font-face, .mobile @font-face simply wont work.

The best bet for anything more than simple teaks is to create your own plug-in that pulls a specific style-sheet for the jetpack mobile version. A plug-in to customize other plug-in, wordpress is getting a bit tricky. happily this is quite easy, create a directory inside your /wp-content/plugins/ directory, let’s say jetpack-mobile-customizer and create a new file called jetpack-mobile-customizer.php with this content:

<?php
/**
 * @package Jetpack Mobile Customizer
 * @version 0.1
 */
/*
Plugin Name: Jetpack Mobile Customizer
*/

// Check if we are on mobile
function jetpackme_is_mobile() {

    // Are Jetpack Mobile functions available?
    if ( ! function_exists( 'jetpack_is_mobile' ) )
        return false;

    // Is Mobile theme showing/not showing?
    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
        return false;

    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'true' )
        return true;


    return true;
}

function jetpackme_add_css() {
    if ( jetpackme_is_mobile()) {
        wp_register_style('custom_jpmobile_style', 
                          '/wp-content/themes/my-child-theme/jpmobile_style.css');
        wp_enqueue_style('custom_jpmobile_style');
    }
}

add_action('wp_enqueue_scripts', 'jetpackme_add_css');

?>

and customize on line 26 your (child) theme and css. Now, just place all the CSS stuff on this file and it will be applied only to the jetpack mobile site.

To customize the number of posts showed on the mobile version (probably 5 posts it’s a bit overwhelming on hand-held devices), just add this code to your plug-in:

function custom_posts_per_page() {
    if ( jetpackme_is_mobile()) {
        return 1; // mobile version posts number
    } else {
        return false;
    }
}

add_filter('pre_option_posts_per_page', 'custom_posts_per_page', 10000);

And to customize the footer? Yes, again we go to the plug-in to add our stuff and hide the other stuff with CSS. On the plug-in add:

function jetpackme_custom_footer() {
    if ( jetpackme_is_mobile()) {
        global $wp;
        $current_url =  trailingslashit( home_url( add_query_arg( array(), $wp->request ) ) );
        echo '<span><a href="'.$current_url.
             '?ak_action=reject_mobile">Go to Desktop Version</a></span>'.
             '<p align="center">&copy; All rights reserved, yadayadayada</p>';
        return false;
    }
}

add_action('wp_mobile_theme_footer', 'jetpackme_custom_footer');

and in the CSS:

footer #site-generator {
        padding: 0 !important;
}

footer #site-generator > a {
        display:none;
}

So, there you go. Some clear ideas how to do the job of customizing the Jetpack Mobile Theme and surviving updates.

And now for a completely free bonus, a full customization of the menu and search. A more modern look and feel with everything hidden (menu items and search form) and of course replacing the ugly “Menu” and down arrow text with the ubiquitous 3 horizontal bars. Just open this blog with a mobile device or force the mobile view on this link.

We are using all the concepts previous explained and the very useful gettext filter. On the plug-in:

// Check if we are on mobile
function jetpackme_is_mobile() {

    // Are Jetpack Mobile functions available?
    if ( ! function_exists( 'jetpack_is_mobile' ) )
        return false;

    // Is Mobile theme showing?
    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
        return false;

    return jetpack_is_mobile();
}

function jetpackme_add_css_js() {
    if ( jetpackme_is_mobile()) {
        wp_register_style('custom_jpmobile_style', 
                          '/wp-content/themes/my-child-theme/jpmobile_style.css');
        wp_enqueue_style('custom_jpmobile_style');

        wp_register_script('custom_jpmobile_script', 
                           '/wp-content/themes/my-child-theme/jpmobile_script.js', 
                           array('jquery'));
    }
}

function fix_menu($translated_text, $text, $domain) {
    if ( jetpackme_is_mobile()) {
		switch ( $translated_text ) {
			case 'Menu' :
				$translated_text = '<span>Menu</span>';
				break;
			case 'Termo' :
				$translated_text = 'Pesquisar';
				break;
		 }
	}

	return $translated_text;
}

add_filter('gettext', 'fix_menu');
add_action('wp_enqueue_scripts', 'jetpackme_add_css_js');

The CSS:

.search-form #s, .menu-search {
	background-color: transparent !important;
}

.menu-search {
	-moz-box-shadow: none !important;
	-webkit-box-shadow: none !important;
	box-shadow: none !important;
	margin: 0 0.6em 0 !important;
	padding: 1% 2.5% !important;
	padding-right: 0 !important;
	padding-bottom: 0 !important;
	margin-bottom: 0 !important;
	width: auto !important;
	height: auto !important;
}

.menu-search::after {
	display:none;
}

#access {
	width:50% !important;
}

#access h3::before {
    content: "\f419";
    color: #666;
	font:1.3em "Genericons";
	line-height:46px;
}

#access h3.menu-toggle {
	color:#000 !important;
	padding: 0 !important;
	width: auto !important;
}

#access h3.menu-toggle span {
	display:inline-block;
	text-indent: -9999px;
}

#access .menu-toggle::after {
	display:none !important;
}

#access ul.nav-menu {
	left:0 !important;
	background-color:#f1f1f1 !important;
	-moz-box-shadow: none !important;
	-webkit-box-shadow: none !important;
	box-shadow: 0 2px 2px -2px #999 !important;
	padding: 0 !important;
	border-bottom:1px solid rgba(0,0,0,0.1) !important;
	margin-top:3px !important;
}

#access ul.nav-menu li {
	margin: 0 0.6em 0 !important;
	padding: 0 2.5% !important;
	border-bottom: 0 !important;
}

#access ul.nav-menu li a {
	display:block !important;
	padding:1em 0 !important;
}

#access ul.nav-menu::before {
	display:none !important;
}

.search-form {
	width:49% !important;
	display:none;
}

.search-form #s {
	border:1px solid #ddd !important;
	color:#999 !important;
	padding: 0.3em !important;
}

.search-form #s:focus {
	font-size: 1em !important;
	color:#000 !important;
	padding: 0.3em !important;
}

And the extra Javascript file loaded in the plug-in:

(function($) {
	$('h3.menu-toggle').click(function() {
		if ($(this).hasClass('toggled-on') == true) {
			$('div.search-form').show(500);
		} else {
			$('div.search-form').hide();
		}
	});
})(jQuery);

Comments, thoughts or other stuff feel free to use the comment box bellow.

Tune-up a Ikea Expedit shelve with a LED Strip

IKEA ExpeditI was tired of looking into my plain, dull, boring, tedious, monstrous Ikea Expedit shelve in the living room. And, it seems that the new trend at the independent furniture shops (ok, the Pakistani at Lisbon downtown) is to apply LED strips to all kind of furnishings: beds, tables, chairs, stools, sinks, whatever… and boom!!! Eureka, the aha moment, why not leave the bed and table alone, but cheer up my shelve! Also it made sense in a functional way, since at mid-light room I can barely see the stuff that i get from the inner guts of it.

Next day, was shopping day for LED strips in Ebay the global marketplace. Now bear with me, the shopping process is crucial for a good development of your project. There are several decisions you must take. First, the length of strip that you need, for the full IKEA Expedit we are talking about 1.47cm * 5 = 7.35m (and give yourself some cut margin and error margin). Next the LED type, the protection rating and color. For the LED types there are two mainstream options 3528 and 5050. They get their numbers because the dimensions of the chip, 3.5mm * 2.8mm for the 3528 and 5.0mm x 5.0mm for the 5050. So the 5050 is bigger than the 3528, are substantially brighter, with an average of 18 lumen Vs 6 lumen, but also more power angry 0.24W vs .08W. So, for decorative lighting your best bet should be the 3528 and for functional lighting or bright environments you should go for the 5050. Also, take care of the number of LEDs per meter, it should be clear now that a meter of strip with 60 3528s should output the same amount of light that of a meter with 20 5050s (but the first will look much more smooth)… now for the protection rating, you can check the full spec here, but i will break it down for you. The first number is for solid particle resistance and the second for the liquid protection. The common IP20, stands for 2 (protection against fingers or similar?!) and 0 (not protected against water), other common available IP in LEDS strips is IP65 (6 – No ingress of dust; complete protection against contact and 5 – Water projected by a nozzle (6.3 mm) against enclosure from any direction shall have no harmful effects). Usually higher the IP, higher the cost of the strip. For me, with 2 young, active and curious cats in the house, the choice was obvious (IP65)… finally, the color is mainly a question of personal taste, but if you want to change the color on the fly, the way to go is a RGB 5050 LEDs strip as each chip has the 3 main colors that combine into the color that you want (or some psychedelic effects).

This guide is for the 4×4 IKEA Expedit shelve, but is easy adaptable to other piece of furniture.

You will start with:
– 2 rolls of 3028 IP65 warm white
– a transformer (more on this later)
– wire for the connections, don’t worry too much about the thickness as the flow of power will be limited, but worry to get a flexible wire, the flexible the better
– electric block connector (for parallel connections, if series you don’t need this but a little more solder..)
– insulation tape
– a virgin IKEA expedit shelve

Tools:
– a multimeter to check continuity
– a soldering iron and some solder
– a wire stripping tool, or a knife or scissor or use or teeth (don’t use the teeth)
– a screwdriver for the electric block connectors
– a X-Acto knife
– a ruler to check out the dimensions is not a bad idea

Other stuff needed:
– a bottle of beer, so when you get thirsty don’t leave the workstation

You start to cut down five 1.47m segments Expedit Suppliesout of the LEDs rolls. The LEDs strips have a scissor mark that repeats itself along the way after some number of LEDs (mine was between each 3 LED). So look for the nearest mark and cut it with precision on the middle. It’s important that you cut cleanly at the middle as will be easer in the soldering step.

Now, you must decide what kind of connection you should do. You can go parallel or series. For parallel you have the advantage of less soldering to do, if one section stops to work the others will continue to, but you will use more wire, block connectors, and it will be a pain to hide the electric circuit if the fitment is in the middle of the room. The series will use less wire, no block connector, it will be easier to hide completely in the back side of the fitment, but much more soldering to do, and if one of the strips go bad (or the connection between) the upstream will also not work.

You should keep in mind a very important detail about LED strips. When you cut a piece in the pre-designated cutting zones, there is a transistor right before the connectors. This transistor will automatically close the circuit for you if there is no upstream continuity. So if you connect in series and connect a 12v transformer (in the right polarity) to the first LED segment it should light up, you don’t need to close the circuit in the other side. If you connect another segment to the first one (again check the polarity, the LEDs strip should have plus and minus markings) it behaves the same, lights up without the need of closing the circuit at the far end.

Expedit Wiring Diagram

Now, for the “funny” stuff, to solder the circuit. With the X-Acto knife remove the protection material (epoxy or silicone) above the solder points. Then with the hot iron melt way the remaining of the protection material. Drop a bit of solder into the solder points, then drop another bit into the end of the stripped wire. Then press and hold the wire against the solder point, and heat it up until both bits of solder melt and fuse. A quick demonstration video:

When it’s all done and fitted, means that is time to calculate the power consumption, and transformer requirements. Each LED uses 0.08W and one meter has 60 LEDs, for the sake of simplicity we will round the 1.47m segments to 1.5m. So each segment has 90 LEDs, 0,08W * 90 = 7.2W per segment. At 12v it gives (7.2 / 12) 0.6amps per segment. For 5 strips in parallel, the total output is 3amps.

To be safe the transformer should output 12v and 3amps (if it’s rated in Watts should be 36W). If you use a less powerfull transformer (let’s say a 1 amp) it can heat up and meltdown. If you feed the circuit with less voltage it will the lights will dim, and as you step down the voltage, eventually it will not light at all. The cost per hour of usage at full throttle is pretty cheap, as 36W/h at 0.20 cents the Kw/h sums at a cost of 0.0072 cents hour….

If all goes well the final result should be this:

expedit_leds