Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a website that displays a specific layout feature only on the homepage, and this is working fine. However, the client has suggested that they would like the website to be bilingual, and so I added a plugin to allow the transition between two languages.

Unfortunately, the plugin adds /?lang=cy to the URL and I fear it's causing my layout feature to break.

The conditional is relatively straight forward:

if (is_front_page()){ ?>
    RENDER HOMEPAGE FEATURE
<?php }

When I choose to switch language, the layout feature disappears.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'm not sure if lang is a reserved/used query variable in WordPress, but if it's not, then adding might help. Use a filter on query_vars like this:

function my_query_vars( $vars ) {
    $vars[] = 'lang';
    return $vars;
}
add_filter( 'query_vars', 'my_query_vars' );

Although WordPress will now know about the language query variable, I'm not sure what's causing your is_front_page() to stop returning true, perhaps it's not about your query variables but about the query itself, because is_front_page() depends on the $wp_query global object.

So how does your language plugin work? If you've set a page with an id of 10 as your front page, then is_front_page() for that page will return true, but if your language plugin is filtering the query and grabbing a page with an id of 50 (which is page 10 translated into Italian) then it's no longer the front page.

Give us a little bit more info about which plugin you're using to handle translations and if you wrote it yourself let us know how it works :)

Cheers!

share|improve this answer
    
I'm using qTranslate, and as far as I can tell, it just doubles the content of each page adding in <!-:en:--> and <!-:cy:--> to separate the languages, I don't think the pages double up as you suggested. –  Dan Hanly Nov 28 '11 at 15:07
1  
@Daniel you can easily check that, before calling is_front_page try to print_r the $wp_query global and see what changes between the two requests (the one with the lang query variable and the one without it). –  kovshenin Nov 28 '11 at 15:24
    
thanks, I'll try this at some point tomorrow! –  Dan Hanly Nov 28 '11 at 16:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.