WordPress, qTranslate, Custom Menu Item Links

On the Food Empowerment Project site, we use mqTranslate, a successor to qTranslate, to manage content in English and Spanish. In conjunction with qTranslate Slug, we get specific urls for pages in English and Spanish, a language switching button in the header, and menus & widgets reflecting the currently selected language.

Menu items which link to pages reflect not only the right language for the menu text, but also automagically link to the correct url for the current language. The challenge I found was with custom menu items. They show the correct text for the menu item by language, but because of the way WordPress handles the “url” of the custom menu item, you can’t use multiple languages in that field.

The right way to fix this, I suppose, would be a custom plugin which extends the custom menu item to allow multiple URLs by language, and then updates the admin interface to show the appropriate URL field for the current language, just as qTranslate does to show the appropriate menu text for the current language (inside the dashboard & when output).

But I didn’t have time for that.

The goal was to add a link in primary navigation menu to another project of Food Empowerment Project, VeganMexicanFood.com. That site has a different url for English and Spanish, but is an external link.

The simple answer I found was to use the wp_nav_menu_objects filter:

function vmf_menu_links($items, $args) {
     if(qtrans_getlanguage() == 'en') {
          return $items;
     }
     foreach ($items as $item) {
          if ($item->ID == '512') {
               $item->url = 'http://www.veganmexicanfood.com/index_es.htm';
          }
     }
     return $items;
}
add_filter('wp_nav_menu_objects', 'vmf_menu_links', 10, 2);

This filter first checks to see if we’re in English – if we are, it just returns the items unchanged. If we aren’t, that means we’re in Spanish (we only have 2 languages). In that case, loop through the items and when you find the item with ID 512 (the link to Vegan Mexican Food), change the url of that item.

Of course this hack hardcodes the ID of the menu item targeted, as well as the url to use. But for a quick hack it works well, and since the site is heavily cached I wasn’t too worried about performance impact. (You can find the ID of the item easily by looking at the CSS where it is output in the menu).

It could be extended as a switch statement to look for multiple languages and substitute appropriate urls.

Taking Chances

brooklyn_bolders2

This week’s Creative Mornings Boston was held at Brooklyn Boulders in Somerville.

Creative Mornings continues to surprise and delight as an event. I think this is the first time I had to sign a safety waiver just to hear a short talk about business.  The morning also starting with the crew from the Blackout Step Team from Tufts, performing an impressive routine (especially for 9am!).
Read more…

Learning from the other 78%

My lightning talk from WordCamp San Francisco has already been posted to WordPress TV! See the embed below.

In trying to cram a longer discussion down into a lightning talk, of course I left out much of what I’d hoped to get to.


Read more…

Talking to Developers about Content

Following up on yesterday’s post, I’ll also be speaking at Confab Higher Ed in November.

confab-speaking-he-14-300

I really enjoyed the conference last year: impressive keynotes; focused, carefully curated set of breakout talks; and a great crowd of motivated, inspired folks fighting the good fight to improve digital experiences for students, prospects, alumni, and faculty across the range of higher education.

My talk this year is “Engineering Influence: Talking to Developers about Content.” I’ve long said that Content Strategy folks need to exert more influence on technology and can’t just “stay out of the conversation” when it turns technical.

How do content people (those who come to the conversation fundamentally concerned with content production, quality, clarity, and experience) talk effectively with technical people (those who come to the conversation fundamentally concerned with a technical system perspective – what to build, maintain, or customize)?

This isn’t to say content strategy folks should try to take over technical architecture, or to give technical folks a pass on their need to care about content and user experience – just to give some tools / techniques for making that conversation more effective.

San Francisco Here I Come

Although it has been a travel-heavy fall this year, I’m super-excited that I’ll be giving a talk at WordCamp San Francisco!

I’m Speaking at WordCamp San Francisco

The camp is taking a different approach this year, mixing sets of lightning talks in between more traditional conference sessions – see the full schedule.  My talk will be in the set of lightning talks titled “WordPress in Context”  and is called “Learning from the other 78%.”

The basic idea is to look more outside the community of believers and see what we can learn from those we rarely talk to – the folks who aren’t at WordCamps or meetups because they aren’t (yet?) users.