WPML Get url without outputting

Actually WordPress lacks a real function to get posts by slug/post-name. But you can use get_page_by_path() for it so you don’t have to use a custom query: if(function_exists(‘icl_object_id’)) { $post = get_page_by_path(‘your-slug’); $id = icl_object_id($post->ID,’post’,true); $link = get_permalink($id); } The only difference here is that you must use the full path i.e. (‘parent-page/sub-page’) if you … Read more

Does changing ‘WPLANG’ in wp-config.php just effect the admin language or does it have other consequences?

WPLANG effects the whole site not just the admin section, you can use it in conjunction with WPML. It basically sets what language you have translations for but you must include a languages folder inside wp-include with the appropriate .mo and .po files. You can also set WPML to use the default languages directory ( … Read more

Make a custom theme translate-ready

To do it properly, you need to generate a valid .mo file and load the text domain in your theme functions.php: function wpse222346_localize_theme() { load_theme_textdomain( ‘your_theme_domain’, get_template_directory() . ‘/languages’ ); } add_action( ‘after_setup_theme’, ‘wpse222346_localize_theme’ ); You can check the WordPress Codex for more info on the load_theme_textdomain function: https://codex.wordpress.org/Function_Reference/load_theme_textdomain Then you would call the translatable … Read more

How to develop a multilingual theme?

Daniel’s answer was very similar, but applied to plugins rather than themes. For that reason I’ll explain how I specifically did it for themes for anyone else who comes across this problem. Create a folder in the root of your theme called “languages” Go to https://wpcentral.io/internationalization/, search for your language and copy the “WordPress Locale” … Read more

Multisite – how to remove the root ‘/’ site?

I use on the root site a small theme for redirect to the languages. A very small theme for locate the language of the users and redirect to the blog of this language. <?php // Browsersprache ermitteln function lang_get_from_browser($allowed_languages, $default_language, $lang_variable = NULL, $strict_mode = TRUE) { // $_SERVER[‘HTTP_ACCEPT_LANGUAGE’] verwenden, wenn keine Sprachvariable mitgegeben wurde … Read more

Add code into on a per page/post basis

As you said per page/post basis, this would work for each post add_action(‘wp_head’, ‘add_link_in_head’); function add_link_in_head() { global $post; if(!empty($post)) { $alternate = get_post_meta($post->ID, ‘alternate’, true); $hreflang = get_post_meta($post->ID, ‘hreflang’, true); if(!empty($alternate) && !empty($hreflang)) { ?> <link rel=”alternate” href=”https://wordpress.stackexchange.com/questions/110260/<?php echo $alternate; ?>” hreflang=”<?php echo $hreflang; ?>” /> <?php } } } If there is no … Read more