Advertisement
mbis

Conditional trailing slashes

Sep 28th, 2020
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. function pm_conditional_trailing_slash_redirect() {
  2.     global $permalink_manager_options;
  3.  
  4.     $trailing_slashes_redirect = (!empty($permalink_manager_options['general']['trailing_slashes_redirect'])) ? $permalink_manager_options['general']['trailing_slashes_redirect'] : false;
  5.  
  6.     if(function_exists('is_product_category') && is_product_category() && $trailing_slashes_redirect) {
  7.         $permalink_manager_options['general']['trailing_slashes'] = 2;
  8.     }
  9. }
  10. add_action('wp', 'pm_conditional_trailing_slash_redirect', 99);
  11.  
  12. function pm_product_cat_trailing_slashes($permalink, $term) {
  13.     if(!empty($term->taxonomy) && (in_array($term->taxonomy, array('product_cat')))) {
  14.         $permalink = untrailingslashit($permalink);
  15.     }
  16.  
  17.     return $permalink;
  18. }
  19. add_filter('permalink_manager_filter_final_term_permalink', 'pm_product_cat_trailing_slashes', 999, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement