/ Published in: PHP
courtesy of mark8barnes
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Plugin Name: EMW Wordpress Hacks Version: 0.2 Plugin URI: http://www.emw.org.uk/ Description: Various hacks to make the bi-lingual site work with two domains. Author: Mark Barnes Author URI: http://www.4-14.org.uk/ */ //Returns the language requested in the URL function emw_get_language() { if ($_GET['lang']) return $_GET['lang']; else { $uri = $_SERVER['REQUEST_URI']; $query = $_SERVER['QUERY_STRING']; } } //Updates the WordPress address function emw_retain_uri($content) { $code = emw_get_language(); if ($code == "en") return "http://www.emw.org.uk"; elseif ($code == "cy") return "http://www.mudiad-efengylaidd.org"; else return "http://".$_SERVER['SERVER_NAME']; } //Redirects the page if wrong domain is used function emw_redirect () { $code = emw_get_language(); $host = $_SERVER['HTTP_HOST']; if ($code=="en" && $host != "www.emw.org.uk") { } elseif ($code=="cy" && $host != "www.mudiad-efengylaidd.org") { } } //Ensures list_pages and similar functions return correct domain name // This function requires Gengo to append language links automatically. function emw_rewrite_link ($link) { if ($code=="en") elseif ($code=="cy") else return $link; } //Adds translation widget function emw_translation_links($args) { echo $before_widget; echo $before_title.$after_title; echo '<div id="change-language">'; the_translations('pre=&post=&inner=&title_exists=&snippet=view_page'); echo '</div>'; echo $after_widget; } } //Registers all custom widgets function emw_widget_init() { register_sidebar_widget('Translation Links', 'emw_translation_links'); } add_action('template_redirect', 'emw_redirect'); add_filter('option_home', 'emw_retain_uri', 1); add_filter('option_siteurl', 'emw_retain_uri', 1); add_filter('page_link', 'emw_rewrite_link', 101); add_filter('post_link', 'emw_rewrite_link', 101); add_filter('category_link', 'emw_rewrite_link', 101); add_filter('category_feed_link', 'emw_rewrite_link', 101); add_action('widgets_init', 'emw_widget_init'); ?>
URL: http://wordpress.org/support/topic/221850