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.