Vancouver WordPress Meetup Talk: Simple Yet Powerful WordPress Hacks
Below you’ll find the code examples for my Vancouver WordPress Meetup group talk Simple Yet Powerful WordPress Hacks held on August 12, 2010. This article will be expanded after the talk but for now it consists only of the code examples themselves.
Replace blog title with a linked image
One of my top 10 pet peeves is sites where you can’t click the logo to get to the home page but have to click the “Home” button. This code block can be inserted in the header.php file and it will insert an image (logo) that links back to the home page and also has the alternate text and link title set to the name of the site.
<div id="blog-title"> <a href="<?php echo get_bloginfo('url') ?>/" title="<?php bloginfo('name') ?>" rel="home"> <img alt="<?php bloginfo('name') ?>" src="<?php echo get_bloginfo('template_url') ?>/imageFolder/imageFile.type" /> </a> </div>
Add WP 3.0 menus to non-WP 3.0 themes
To add WP 3.0 menus to themes that were built before the new version of WordPress or don’t have them built in you need to activate the menu function in functions.php and then add a call to the menu in your template file.
Add to functions.php:
register_nav_menus(
array(
'menuName' =>__('Menu Name'),
'2ndMenu' =>__('2nd Menu'),
)
);Add to template file:
<?php wp_nav_menu(array( 'theme_location' => 'primary' )); ?>
Note that the theme_location call points to the name of the menu as set in functions.php. To target the menu name set inside WordPress use this code instead:
<?php wp_nav_menu(array( 'name' => 'Menu Name' )); ?>
Highlight current page or category in menu
I’ve already written an extensive article on this subject that can be found here. The core of the CSS code is this style:
.current-menu-item,
.current-page-ancestor,
.current-post-ancestor {
... style info goes here ...
}Custom page template in 5 lines of code
To create a custom page template simply insert the following 5 lines of code at the top of your template file and give it a name other than “whatever”. Once saved (as something other than page.php) it will appear as one of your template options inside WordPress.
<?php /* Template Name: Whatever */ ?>
Add Featured Image (thumbnail) functionality to your theme
To activate the Featured Image panel in WordPress admin an enable the function you need to add a small piece of code to the functions.php file. Once this is done and Featured Images have been defined you can call them from within any template file using one of the calls below.
In functions.php:
add_theme_support( 'post-thumbnails' );
In theme file:
<?php the_post_thumbnail(); ?>The above call will produce the thumbnail in the size defined inside WordPress admin under Settings -> Media. To call a different size use one of the following:
the_post_thumbnail('thumbnail');
the_post_thumbnail('medium');
the_post_thumbnail('large');
the_post_thumbnail(array(nnn,nnn));For the last one replace ‘nnn’ with any pixel width and height.
Make Web Not War 2010 – a recap
With guitarpick dogtags, military paraphranalia and a notebook with the cover text “Why the f@&#* is Microsoft doing this?” Make Web Not War set a new standard for conferences.
The first words out of my mouth as I stepped off the plane in Montreal Wednesday afternoon were “What the Fuck!” (yes, I’m a real class act). Crossing the threshold from plane interior to airport gangway was like walking into a furnace. It was, at least to me, unbearably hot and I was in a rush to get out of the plane and to a washroom to blow my nose. Five hours earlier I found myself on a WestJet flight crossing the great Canadian landscape on my way to the almost mythical French portion of Canada. In my bag, my camera, my laptop and the bare necessities. As I made my way through Trudeau International Airport on the hunt for a cab all I could think was “I hope this cold doesn’t claim my voice as its victim” interspersed with “I’m late, I’m late, I’m late, for a very important date”. The plane had taken a good 1 hour extra on its leisurely trip across the prairies, rush-hour was fast approaching and I knew that somewhere inside this Francophone metropol Angie Lim and her crack team of Microsoft event planners were waiting for my arrival.
And now for something completely different
Make Web Not War has been pushed as a conference that falls well outside the norm from the start. And with good reason. Entering the in itself fascinating location of Espace Reunion in the Outremont district I was met with military paraphranalia interspersed with glossy tech. There were gas masks, Dell laptops, ammunition cases, cammo clad couches, Beatles Rock Band and a huge green screen. I’ve been to quite a few conferences and I can tell you this is not common fare. But it set the right tone right off the bat.
This was Wednesday afternoon and the place was alight with frenzied activity. Microphones were being tested, screens hung, gear placed, names checked, I felt like I had walked right into a finely tuned machine room. The Master of Events Angie popped up to greet me but was soon pulled away to deal with a technical issue and before I knew it I was wisked away to a delightful dinner with the crew and the other speakers. Never mind the tech test – there was networking to be done.
Guitar picks and code languages
First impressions are vitally important, especially for public events like this. And the registration process often sets the tone for the entire conference. Make Web Not War was no exception, and that’s a good thing: When you are handed a dog tag chain full of colourful guitarpicks and a notebook with the cover text “Why the f@&#* is Microsoft doing this?” you know instantly this isn’t going to be yet another one of those boring conferences. Each attendee was handed a set of 5 guitarpicks, some of them doubles, and told that to get into the after party they needed to trade picks with the other attendees to get a complete set of 5 picks, each representing an open source code languages Microsoft supports.
Microsoft = Interop
The guitar picks were more than just nifty party tricks to force some interaction between the attendees: The whole point of the conference was to tell people that Microsoft is now 100% committed to interoperability. In other words you can now run open source languages, apps and software on Microsoft platforms without any problems. The web is platform agnostic and Microsoft has heard that message loud and clear. Now they want you to know they are in full support of it. Which is why they had Joël Perras, a dev for CakePHP and Lithium, as the keynote speaker, why the FTW (For The Web) contest was featured around Open Data and why they had me presenting my talk on developing WordPress sites using Microsoft applications. Like Joël said, “Interoperability is not a feature, it’s a requirement”. And we all got it.
Open communities
As usual I spent more time talking to people and soaking in the atmosphere than I did actually attending sessions at Make Web Not War. What I walked away with was a realization that the Montreal dev community is an astonishingly open one. In general I find people who work in the online realm to be cliquy to the point of isolationist, but not so in Montreal. Maybe it’s the Francophone culture, maybe it was just the overall air of the event itself, but I found more people open to frank discussions and inclusion than what I’m used to. Which was awesome. On top of that Microsoft had sent out a score of great people to further interaction. In all the sense of openness was everywhere and I was left with a feeling of inclusion, of being part of a greater community.
“Nice to finally meet you IRL”
Having put on a couple of events myself, most notably the 12×12 Vancouver Photo Marathon, I can tell you it’s no small feat. Which makes the hitch-free Make Web Not War all the more impressive. And for that mad props go out to the whole Microsoft team and in particular the aforementioned Angie Lim. I’ve dealt with her on several occasions in the past, but only by email so to me it was an added bonus to finally meet her in person. Or as Angie so geekfully put it “Nice to finally meet you IRL”. (Seriously, she is the only person who can say stuff like that without coming off like the biggest nerd ever).
Make Web Not War was filled with interaction, technology, knowledge and a sense of positive development. I left feeling like I was part of something bigger, that working with the web means I’m working with some of the brightest and most original people on the planet. And for that I am honoured.
FTW contest – going beyond the obvious
The FTW (For The Web) contest was a subset of the conference and it deserves special mention. The mandate was simple if not vague: Make an application using Open Data. It’s the kind of mandate that drives me insane, but other more focussed people were able to make some truly amazing stuff out of it. The finalists, TaxiCity – a student project from the Centre for Digital Media in Vancouver created by Mohamed El Eryan, Dashan Yue, Seth Marinello, Jordan Braun, Sagar Datta, Dhruv Adhia, and Ryleigh Kostash, Find-a-Home created by Timothy Dalby, and Project Tholus created by Francois Mazerolle showed that Open Data can be used to create surprising and original applications that go way beyond the standard data feeding and map overlays we are used to seeing. The winner, Find-A-Home, was especially impressive and I can see almost endless applications for this novel yet original idea down the road. I only wish I had come up with it first.
Further reading
Make Web Not War (official site)
Dan Menard’s recap
Cory Fowler’s recap
Brendan Sera-Shriar linkfest
My Web Not War photoset on Flickr
The official WebNotWar Flickr Pool
The Unholy Quatern at Web Not War 2010 in Montreal

UPDATE: The Unholy Quatern session I did at Web Not War 2010 was loosely based on an article I wrote for the Microsoft Expression Newsletter last year. To get a more in-depth walk-through of my work process and some more code examples etc take a look at the original article found here.
After 8 years in Canada I finally find myself in the mythical French portion of the country, more specifically the Beaumont district in Montreal, Quebec. Why? To talk WordPress and Expression Web to the attendees at the Web Not War conference. I’ll be posting more on this later but for now here are the vital links for my talk. The slides will be here shortly. Check back for updates.
Links
WordPress template tools for Expression web
WordPress on your computer: Web Platform Installer or BitNami
Sync your files: Live Mesh
Webcast: An Intimate and Enlightening View into Microsoft Expression Web 3
I’m doing a 1 hour live webcast with Microsoft Canada demonstrating advanced WordPress customization with Expression Web 3 on April 6th, and you are welcome to join. It will be an extended version of my MIX10 session with more demos and more time for questions. All you have to do to participate is register. Full writeup below:
REGISTER
Invitation Code: 0781DA
Tuesday, April 6th, 2010
Start Time: 11:00AM PST (02:00 PM EST)
Webcast Duration: 60 min
Questions about these events?
Call us at 1-888-789-7770
A follow up to Paul Laberge’s “101” webcast, Expression Web MVP and WordPress hacker Morten Rand-Hendriksen takes you through an intimate and enlightening look into his day-to-day work process. He specializes in building solid standards-based websites on the WordPress platform using Microsoft web technologies and Expression Web. The session takes you through real-life examples of customer projects and pulls back the curtain on a work process that employs what Morten jokingly refers to as the “Unholy Quatern” – Microsoft’s Expression Web 3, Web Platform Installer and Mesh combined with the open-source publishing platform WordPress. Combining these four technologies Morten has developed a process in which rapid site debugging, prototyping and implementation becomes a reality.
Learn the inner workings of WordPress and how to use its theme engine to build pretty much any website you can think of using Expression Web 3 and see how using simple web technologies like WPI and Mesh can make your life as a CMS dev/igner much easier.
MIX10 Session and Supporting Documents
Above is my MIX10 session A Case Study: Rapid WordPress Design and Prototyping with Expression Web 3 in its entirety in Silverlight video format. It can be blown up to full screen and I highly recommend it as there are code examples.
In the session I referenced a bunch of different technologies and applications I use on a day-to-day basis. For those in attendance and those watching on the web here is the exhaustive list of links and tools for you to play around with. I will post a link to the video version of my session when it becomes available approximately 24 hours after the session itself.
The Unholy Quatern
The Unholy Quatern consists of 4 basic elements;
If you are only installing WordPress on your local computer there is no need to get WordPress from the original source – the Web Platform Installer will handle the installation for you. The same applies if you are using a different CMS under the WPI.
NOTE: If you are working in Windows 7 it will be necessary to run Expression Web 3 as Administrator if you want to set up the WPI version of WordPress as a site. Otherwise Expression Web 3 will not have permission to write to the folder and you’ll be banging your head against a wall for hours trying to figure out why it’s not working.
WordPress Code Snippets for Expression Web
I have created a downloadable version of the WordPress code snippets used in the session. They are availalbe – and frequently updated – at the Expression Gallery. The snippets work with any version of Expression Web and are quite literally plug-and-play. The current version of the WordPress Template Tools comes with a special snippet that lets you create new snippets. Snippets in the current version are:
- Custom Page Template tag
- Custom Field tag
- PHP parsing Custom Field
- Conditional Custom Field
- Image as Header
- Get blog/site URL
- Get current theme URL
- Get blog/site name
- Get blog description
- PHP include
Most of these are plug-and-play and those that are not are fairly easy to understand. They are all 100% standards-based and use current and up-to-date WordPress template tags.
I update the WordPress Template Tools on a random basis whenever I feel there is a new tag that will be useful for other people. If you have an idea for a template tag not currently in the list feel free to contact me with the suggestion.







