WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional Statement to Show Alternate Header Information (5 posts)

  1. alvaradopau
    Member
    Posted 2 years ago #

    Hi everyone, thanks in advance for the help.

    I'm setting up a multilingual site with WPML and I've solved all the issues with multiple sidebars and widgets, but I cannot work out the header. Right now my header is an image map and some text, which are encased in the functions.php file on my theme (something like "before header info, include this," and the image map code).

    What I'm trying to figure out is how to tell wordpress "If the directory is /en/ show this instead of that" where "this" would be an alternative image map and "that" the original one. I need to cover all the pages that might be inside the /en/ directory since new translations are added all the time.

    The only thread I found remotely on subject was this: http://wordpress.org/support/topic/if-conditional-for-a-directory-or-when-on-blog, which included this piece of code:

    <?php
    if(preg_match("/\/blog\//",$_SERVER['REQUEST_URI'])){
       //if /blog/ is anywhere in the URL..
    }else{
       //if /blog/ is not in URL
    }
    ?>

    But that didn't work (I did change "blog" for "en").

    I'm thinking it has to be some variation of the above, but I cannot work it out.

    Thanks so much in advance!

  2. LucP
    Member
    Posted 2 years ago #

    Actually, directories have nothing to do with the way WordPress and WPML create there urls. They are dynamic rewrites, so your searchquery was the problem (that's why you got so few good results)

    WPML has a constant you can check:

    <?php 
    
       if( ICL_LANGUAGE_CODE == 'en' ){
            //your header stuff for the english version
       }else{
            //your header stuff for the other languages
       }
    
    ?>

    Good luck!

  3. alvaradopau
    Member
    Posted 2 years ago #

    That makes sense. I think I'm messing up with the function code though since it doesn't quite work:

    add_action('pagelines_inside_top_branding','myhook');
    function myhook(){
    ?>
    <?php if(ICL_LANGUAGE_CODE=='en'){
    ENGLISH HEADER
    }else{
    SPANISH HEADER
    }
    ?>
    <?php
    }

    What am I doing wrong here? Thank you so much for the help!

  4. LucP
    Member
    Posted 2 years ago #

    I'm not really that familiar with the pagelines theme and I don't know what the 'pagelines_inside_top_branding' line does... I think your problem starts there.

    My guess is they can help you further on the pagelines forum: http://www.pagelines.com/forum/

  5. alvaradopau
    Member
    Posted 2 years ago #

    The Pagelines forum is for paid developer or professional memberships and those are quite expensive... You cannot post a question if not registered.

    I figured it out though, I was missing some <?php openers and closers. This is the version that worked if anyone is looking for it:

    add_action('pagelines_inside_top_branding','myhook');
    function myhook(){
    ?><?php if(ICL_LANGUAGE_CODE=='en'){
    ?>
    ENGLISH HEADER CODE
    <?php
    }else{
    ?>
    SPANISH HEADER CODE
    <?php
    }
    ?>
    <?php
    }

    Thanks a lot for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic