Advertisement
retesere20

remove category base wp

Jun 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1.  
  2. // removing category base (p.s. at this moment, you can use . (dot) in SETTINGS>PERMALINKS >Category base to get same result :)
  3.  
  4.  
  5.  
  6.  
  7. if (definedTRUE("CatBase_REMOVING_CHECKED")){
  8. add_filter( 'user_trailingslashit', 'fix_slash__my554', 55, 2 );
  9. function fix_slash__my554( $string, $type ){global $wp_rewrite;
  10. //this below "IF" condition checks if trailing slash is the not last char of PRETY PERMALINKS(i.e. /%postname% )
  11. //If so, then the next codes cause /CATEGORY/my-cat to be redirected to /my-cat.
  12. //If not, then nothing will happen, and default will be....
  13. //so, i have just removed..
  14. //if ( $wp_rewrite->use_trailing_slashes == false ) {
  15. if ( $type != 'single' && $type != 'category' ) return trailingslashit( $string );
  16. if ( $type == 'single' && ( strpos( $string, '.html/' ) !== false ) ) {return trailingslashit( $string );}
  17. if ( $type == 'category' && ( strpos( $string, 'category' ) !== false ) ) {
  18. return trailingslashit(str_replace( "/category/", "/", $string ));
  19. }
  20. if ( $type == 'category' ) { return trailingslashit( $string ); }
  21. //}
  22. //MyFlush__MLSS(false);
  23. return $string;
  24. }
  25.  
  26.  
  27. //check if category slug is to be removed... (p.s. at this moment, you can use . (dot) in SETTINGS>PERMALINKS >Category base to get same result :)
  28. add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules3332' );
  29. function vipx_filter_category_rewrite_rules3332( $rules ) {
  30. $categories = get_categories( array( 'hide_empty' => false ) );
  31. if ( is_array( $categories ) && ! empty( $categories ) ) {
  32. $slugs = array();
  33. foreach ( $categories as $category ) {
  34. if ( is_object( $category ) && ! is_wp_error( $category ) ) {
  35. if ( 0 == $category->category_parent ) {
  36. $slugs[] = $category->slug;
  37. } else {
  38. $slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
  39. }
  40. }
  41. }
  42. if ( ! empty( $slugs ) ) {
  43. $rules = array();
  44.  
  45. foreach ( $slugs as $slug ) {
  46. $rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
  47. $rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
  48. $rules[ '(' . $slug . ')(/page/(\d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
  49. }
  50. }
  51. }
  52. return $rules;
  53. }
  54.  
  55. add_filter( 'term_link', 'func352511', 11, 3 ); function func352511($url,$term,$taxonomy){
  56. $x=str_ireplace( remove_double_slashes(homeURL__MLSS.'/category/') , remove_double_slashes(homeURL__MLSS.'/'), $url);
  57. return $x;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement