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.

The WPML plugin filter's home_url in order to provide a link to the home page specific to the language you are viewing. (So if you are reading a Spanish page home_url() will point you to http://example.com/es). I need to disable for a site that will not have language-specific homepages. So I went digging into the WPML plugin, which is essentially launched in a typical way:

global $sitepress;
$sitepress = new SitePress();

Then in the class's constructor the offending filter is added:

add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );

With the class's callback method being (for reference):

// filter for WP home_url function
function home_url( $url, $path, $orig_scheme, $blog_id )
{
    // exception for get_page_num_link and language_negotiation_type = 3
    if ( $this->settings[ 'language_negotiation_type' ] == 3 ) {
        $debug_backtrace = debug_backtrace();
        if ( !empty( $debug_backtrace[ 6 ] ) && $debug_backtrace[ 6 ][ 'function' ] == 'get_pagenum_link' )
            return $url;
    }

    remove_filter( 'home_url', array( $this, 'home_url' ), 1 );
    // only apply this for home url - not for posts or page permalinks since this filter is called there too
    if ( ( did_action( 'template_redirect' ) && rtrim( $url, '/' ) == rtrim( get_home_url(), '/' ) ) || $path == '/' ) {
        $url = $this->convert_url( $url );
    }
    add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );

    return $url;
}

This seems like it should be a straight-forward case of remove_filter. However adding the following to functions.php (admittedly it should maybe be in a site-specific plugin) does not seem to remove the filter and the main logo (which uses the home_url() function is still pointing to the language-specific homepage).

function rar_remove_wpml_home_filter(){
    global $sitepress;
    remove_filter( 'home_url', array( $sitepress, 'home_url' ), 1, 4 );
}
add_action( 'plugins_loaded', 'rar_remove_wpml_home_filter' );

I've also tried running this on the init hook. It seems I must me missing something obvious.

share|improve this question
    
Take a look at this question and answer, stackoverflow.com/questions/19140567/… –  Rajeev Vyas Apr 16 at 15:04

2 Answers 2

up vote 1 down vote accepted

I found that it required removing 4 filters/actions to undo WPML's home_url modification. Since I didn't know what else this might break, I ended up changing my site's logo to use site_url() which in my case was the same, but not changed by WPML.

function disable_things(){
    remove_filter( 'page_link', array( $this, 'permalink_filter' ), 1, 2 );
    remove_action( 'wp_head', array( $this, 'front_end_js' ) );
    remove_filter( 'feed_link', array( $this, 'feed_link' ) );
    remove_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );
}
add_action( 'wp_head', 'disable_things', 20 );
share|improve this answer

What about taking a different approach?

Keep the filter and in WPML -> Languages, chose "Use directory for default language".

There you can specify a static file or create a "Root page".

This page won't be connected to any language. It won't even show the language switcher (unless you use a custom template and play with the code).

share|improve this answer

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.