Advertisement
mbis

Inherit the custom permalink from original page

Mar 30th, 2020
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. /**
  2.  * Inherit the custom permalink from original page
  3.  */
  4. function pm_inherit_permalinks($default_uri, $post_name, $post, $slug, $native_uri) {
  5.     global $sitepress, $permalink_manager_uris;
  6.  
  7.     // Do not change native permalinks or posts assigned to another categories
  8.     if(($native_uri == true) || empty($post_name) || empty($post->ID)) { return $default_uri; }
  9.  
  10.     // Check if WPML plugin is enabled
  11.     if(is_object($sitepress)) {
  12.         // Get default language
  13.         $def_lang = $sitepress->get_default_language();
  14.  
  15.         // Get original ID
  16.         $original_id = apply_filters('wpml_object_id', $post->ID, $post->post_type, false, $def_lang);
  17.  
  18.         // Get original custom permalink
  19.         $default_uri = (!empty($permalink_manager_uris[$original_id])) ? $permalink_manager_uris[$original_id] : $default_uri;
  20.     }
  21.  
  22.     return $default_uri;
  23. }
  24. add_filter('permalink_manager_filter_default_post_uri', 'pm_inherit_permalinks', 999, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement