Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Inherit the custom permalink from original page
- */
- function pm_inherit_permalinks($default_uri, $post_name, $post, $slug, $native_uri) {
- global $sitepress, $permalink_manager_uris;
- // Do not change native permalinks or posts assigned to another categories
- if(($native_uri == true) || empty($post_name) || empty($post->ID)) { return $default_uri; }
- // Check if WPML plugin is enabled
- if(is_object($sitepress)) {
- // Get default language
- $def_lang = $sitepress->get_default_language();
- // Get original ID
- $original_id = apply_filters('wpml_object_id', $post->ID, $post->post_type, false, $def_lang);
- // Get original custom permalink
- $default_uri = (!empty($permalink_manager_uris[$original_id])) ? $permalink_manager_uris[$original_id] : $default_uri;
- }
- return $default_uri;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_inherit_permalinks', 999, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement