0

I'm using WooCommerce to create an online shop. Some products are tagged with an "outlet" tag. I'm currently showing them via a menu item linked to the "outlet" product tag archive. The current URL of the archive is domain.com/tags/outlet/ but I want it to be domain.com/outlet/. I need this custom rewrite only for the "outlet" tag archive, not for all the tags. It's possible to do so? Thanks.

0

@ederico-dondi

On your tag listing page, Wordpress is getting the content of the page from your url querystring. In your case, there is "tag" in your url so it will understand that you are on tag page. If you will remove tag then it will not show data of tag. for example. the below code will remove tag from your url.

function customremovetag( $string, $type ) {
  global $wp_rewrite;
    $string =   str_replace('tag', '', $string);


  if ( $wp_rewrite->use_trailing_slashes == false ) {
    if ( $type != 'single' && $type != 'category' )
      return trailingslashit( $string );

    if ( $type == 'single' && ( strpos( $string, '.html/' ) !== false ) )
      return trailingslashit( $string );

    if ( $type == 'category' && ( strpos( $string, 'category' ) !== false ) ){
      $aa_g = str_replace( "/category/", "/", $string );
      return trailingslashit( $aa_g );
    }
    if ( $type == 'category' )
      return trailingslashit( $string );
  }

  return $string;
}
add_filter( 'user_trailingslashit', 'customremovetag', 55, 2 );

But also it will break your page. May be there may exist other solution for your question. But I think it can break your page content after remove the "tag" from your url. Try my code and see. Thankyou.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy