Advertisement
mbis

Use theme options in custom permalinks

Jan 25th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. function pm_support_theme_options($uri) {
  2.     $fields = array(
  3.         'washers_soft', // %__washers_soft%
  4.         'washers_hard', // %__washers_hard%
  5.         'washers_front' // %__washers_front%
  6.     );
  7.  
  8.     foreach($fields as $field) {
  9.         if(strpos($uri, "%__{$field}%") !== false) {
  10.             $field_value = get_option($field);
  11.            
  12.             $uri = str_replace("%__{$field}%", sanitize_title($field_value), $uri);
  13.         }
  14.     }
  15.  
  16.     return $uri;
  17. }
  18. add_filter('permalink_manager_filter_default_post_uri', 'pm_support_theme_options', 0, 3);
  19. add_filter('permalink_manager_filter_default_term_uri', 'pm_support_theme_options', 0, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement