We would like this WordPress Blog, that has the Twenty Ten theme, to be better adapted for mobile phone use (that being Android, iOS, Blackberry) regarding its look and usability. Several comments on the blog have asked about this, and hope they are โviewingโ now. Weโve determined that the mobile phone device is the priority, and that, for now, mobile tablets do not need such urgent attention.
With WordPress Blogs you can go down the path of getting a mobile-friendly theme to start with, or apply a third-party plugin such as WordPress Mobile Pack, or do it yourself. We are going to opt for โdo it yourselfโ and learn more about the innards of the blogโs styling as a result. Porquoi? How can you learn without knowing โnowโ โฆ so to speak? Well, thatโs the beauty of using an HTML examiner such as Firebug โฆ sorry to go on and on and on and on and on about Firebug โฆ but really โฆ for DIY WordPress work, such a tool is worth its weight in gold.
Am going to show you the first sweep of changes with a point form in โblackโ and an action taken as a result in โredโ below โฆ
- settle on a policy regarding clutter โฆ will you reduce data? never? โฆ am aiming for โneverโ but may be deluded here
- determine a PHP way to detect for a mobile phone device (tablets seem okay)
<?php
โฆ applied in header.php coding
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if ($iphone || $android || $ipod || $blackberry) { // thanks to http://www.phpmysqlscript.com/2012/03/detecting-users-screen-size-and.html
// these are the devices we want to work with with our changes today
}
// ...
// ...
?> - (you may need to) determine a Javascript way to detect for a mobile phone device (tablets seem okay) โฆ try reading Javascript screen width detection ideas as a start
- settle on a โmetaโ โviewportโ tag to your liking โฆ personal preference leads to โฆ
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.25, maximum-scale=8, user-scalable=yes" />
โฆ applied in header.php coding - review the look and usability of the blog โฆ spent quite some time at this, because you want to know setting above is user-friendly, then think about the look
- round up the โimgโ elements that are too big and do something about them โฆ used Firebug to point at these and identify their โidโโs and/or โclassโ (and perhaps their tag type) โฆ this lead to bold change in WordPress functions.php regarding the header images as per โฆ
define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
$nfty = 940;
$oneg = 198;
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if ($iphone || $android || $ipod || $blackberry) { // thanks to http://www.phpmysqlscript.com/2012/03/detecting-users-screen-size-and.html
$nfty = $nfty / 2;
$oneg = $oneg / 2;
}
// The height and width of your custom header. You can hook into the theme's own filters to change these values.
// Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', $nfty ) ); //940 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', $oneg ) ); //198 ) );
- have a look at the site with Firebug and point at the wider offending elements, then look over at the right hand side CSS section to see what some local CSS changes might achieve โฆ this lead to bold change in WordPress header.php as per โฆ
<style>
// ...
// ...
// ...
li.eight {
background-image: url('http://www.rjmprogramming.com.au/PHP/eight.jpg');
background-position: left;
background-repeat: no-repeat;
background-size: 128px 80px;
height: 150px;
text-indent: 0px;
}
<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if ($iphone || $android || $ipod || $blackberry) { // thanks to http://www.phpmysqlscript.com/2012/03/detecting-users-screen-size-and.html
echo "n #access .menu-header, div.menu, #colophon, #branding, #main, #wrapper { width: 580px; } n"; // 470px; }
}
// ...
$hrc = rand(0, 10);
$hrcarray = array("black", "red", "blue", "purple", "maroon", "teal", "brown", "orange", "olive", "lime", "green");
// ...
// ...
// ...
</style>
- check the blog posting wording does not need any manual horizontal scrolling โฆ the direct result of this analysis is the hard-thought-about โ580โ in
echo "n #access .menu-header, div.menu, #colophon, #branding, #main, #wrapper { width: 580px; } n"; // 470px; }
in code snippet above โฆ and the windowScrollBy() in โฆecho "n if (1 == 1) { if (document.URL.indexOf('?') != -1) { location.href='#main'; window.scrollBy(36,220); } else { window.scrollBy(36,0); } n";
โฆ and all this, along with an โonloadโ intervention strategy in the aforesaidmentioned โimg_alt()โ function mentioned in CSS Background Colour Usage Primer Tutorial as per โฆ
function img_alt() {
<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$blackberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if ($iphone || $android || $ipod || $blackberry) { // thanks to http://www.phpmysqlscript.com/2012/03/detecting-users-screen-size-and.html
echo "n if (1 == 1) { if (document.URL.indexOf('?') != -1) { location.href='#main'; window.scrollBy(36,220); } else { window.scrollBy(36,0); } n";
} else {
echo "n if (1 == 2) { n";
}
?>
var ilis, clis;
var nfo, nfos;
var lis = document.getElementsByTagName("li");
for (ilis=0; ilis<lis.length; ilis++) {
clis = " " + lis[ilis].className + " ";
if (clis.indexOf(" page-item-80 ") != -1) {
lis[ilis].innerHTML = lis[ilis].innerHTML.replace(/ Statement/g, "");
} else if (clis.indexOf(" page-item-189 ") != -1) {
lis[ilis].innerHTML = lis[ilis].innerHTML.replace(/One Image Site/g, "1Image");
} else if (clis.indexOf(" page-item-366 ") != -1) {
lis[ilis].innerHTML = lis[ilis].innerHTML.replace(/All Posts/g, "All");
}
}
lis = document.getElementsByTagName("a");
for (ilis=0; ilis<lis.length; ilis++) {
if (lis[ilis].innerHTML.indexOf("pink;") != -1) {
lis[ilis].innerHTML = lis[ilis].innerHTML.replace("pink;", "pink;width:180px;"); //212px;");
}
}
var h1st = document.getElementById("site-title");
h1st.style.width = "250px"; //"350px";
h1st.style.marginTop = "-34px";
h1st.style.marginLeft = "20px";
h1st = document.getElementById("site-description");
h1st.style.position = "absolute";
h1st.style.left = "80px";
h1st.style.top = "35px";
h1st.style.fontSize = "8px";
h1st.style.marginLeft = "36px"; //"350px";
h1st = document.getElementById("site-info");
h1st.style.width = "250px"; // "350px";
h1st = document.getElementById("mywtoi");
if (h1st != null) {
h1st.style.width = "190px"; //"212px";
h1st.style.height = "254px"; //"282px";
}
h1st = document.getElementById("content");
if (h1st != null) {
h1st.style.width = "320px";
}
}
var osf=document.getElementById('marquee-style-rss-news-ticker');
// ...
// ...
โฆ resulted in a look like for our tutorial image - check the workings of โselectโ tags and check that they function โฆ any โwindow.location=โblahโ;โ type of code should become โlocation.href=โblahโ;โ โฆ we talked about this previously with Safari iPad Issue with Window.Open and Window.Location Primer Tutorial
- as far as usability goes, for blog calls of particular sets of postings, is there relevance above the fold straight away? โฆ no โฆ not good so we made that change that goes
echo "n if (1 == 1) { if (document.URL.indexOf('?') != -1) { location.href='#main'; window.scrollBy(36,250); } else { window.scrollBy(36,0); } n";
as above - check out other parts of the domain with links to the blog (maybe via โselectโ tags) that they function โฆ we found โlocation.href=โblahโ;โ issues on the landing page
- keep looking, and using yourself, and see if feedback can help, because you will be unlikely to have all the mobile devices to test out there โฆ doh! โฆ any feedback ( or โfeedbackโ email or โemail a friend with invitation to try this blog on their mobileโ email ) would be greatly appreciated?!
Youโll see throughout the code snippets the generic usefulness of the great advice from this link.
Of course, it goes without saying, that we would appreciate your feedback, as a comment (or โfeedbackโ email or โinvitation to a friend to try this blogโ email ), of your experience accessing this blog on your mobile phone. Hope you try it out, and thanks if you do.
Did you know?
The investigations and analysis of HTML required by this โDIYโ PHP/HTML/CSS were facilitated by the use of the Firefox web browser and a very useful add-on called Firebug which you may want more information about here, and which is commonly used to debug client-side Javascript and HTML. As for todayโs usage, Firebug is also extremely useful in deconstructing how a web page was created. The other simple wonderful tool for this is the web browserโs equivalent menu command like View->Page Source (or sometimes equivalent of right-click Page Source). Firebug has a sister product called FirePHP which helps debug server-side PHP and Ajax work. Please donโt mind me โฆ am sold on Firebug with Firefox, but there are many alternatives (eg. Safari and Inspector (built into Safari) via Develop->Show Web Inspector) โฆ and there are others (with other web browsers).
If this was interesting you may be interested in this too.
19 Responses to WordPress Blog Mobile Phone Friendly Primer Tutorial