S
S
seok802021-09-10 18:30:57
WordPress
seok80, 2021-09-10 18:30:57

How to remove slash at the end of url in wordpress?

Made a multisite. A slash is displayed at the end of each page test.dptrans.com.ua/arenda-avtovyishki.html
Found the code. Everything is working. But how to bind this code to woocomerce categories? It is to make the slash disappear in the woocomerce categories. How?

add_filter( 'user_trailingslashit', 'no_page_slash', 70, 2 );
function no_page_slash( $string, $type ){
   global $wp_rewrite;

  if( 'page' === $type && $wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes )
    $string = untrailingslashit( $string );
  
  if( 'single' === $type && $wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes )
    $string = untrailingslashit( $string );
  
  if( 'category' === $type && $wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes )
    $string = untrailingslashit( $string );
  if( 'product_cat' === $type && $wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes )
    $string = untrailingslashit( $string );
  

   return $string;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-09-10
@artzolin

$string = 'https://example.loc/2021/09/10/has-content/';
$string = preg_replace( '/(\/$)/', '', $string );
var_dump( $string );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question