Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Fran Mendoza

    (@franmglez92)

    Hi there,
    hope you are doing well! ??

    Unfortunately, is not possible to change the brand’s permalink in the free version of the plugin, we are sorry.

    But you can change the “product-brands” slug by a custom one, for this, you have to add the next code in the functions.php of your active theme, replacing the “product-brands” text with the one you want.

    if( defined( 'YITH_WCBR' ) && ! function_exists( 'yith_wcbr_change_taxonomy_rewrite' ) ){
     function yith_wcbr_change_taxonomy_rewrite(){
     return 'product-brands';
       }
     add_filter( 'yith_wcbr_taxonomy_rewrite', 'yith_wcbr_change_taxonomy_rewrite' );
    }

    Could you check it and let us know, please?
    ?
    Have a nice day!

    Thread Starter kastriotsula

    (@kastriotsula)

    Hello @franmglez92, thank you for your response!

    What I did is this:

    1) Removed the /blog/ slug from custom permalink and now i have just this:

    /%category%/%postname%/

    2) Added custom function that adds prefix /blog/ only on posts with this code here:

    
    function add_rewrite_rules( $wp_rewrite )
    {
        $new_rules = array(
            'blog/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1),
        );
    
        $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }
    add_action('generate_rewrite_rules', 'add_rewrite_rules'); 
    
    function change_blog_links($post_link, $id=0){
    
        $post = get_post($id);
    
        if( is_object($post) && $post->post_type == 'post'){
            return home_url('/blog/'. $post->post_name.'/');
        }
    
        return $post_link;
    }
    add_filter('post_link', 'change_blog_links', 1, 3);
    
    

    3) Changed the permalink with the code you gave me to this:

    if( defined( 'YITH_WCBR' ) && ! function_exists( 'yith_wcbr_change_taxonomy_rewrite' ) ){
     function yith_wcbr_change_taxonomy_rewrite(){
     return 'brands';
       }
     add_filter( 'yith_wcbr_taxonomy_rewrite', 'yith_wcbr_change_taxonomy_rewrite' );
    }
    

    Now the only things that is not working is that i wanna use the /blog/ prefix for the category post too, how can I do that?

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi there,

    In order to achieve what you need, try with this code:

    function filter_category_link( $termlink, $term_term_id ) { 
        $termlink = home_url('/blog/'. $get_term( $term_term_id )->name .'/');
        return $termlink; 
    }; 
             
    add_filter( 'category_link', 'filter_category_link', 10, 2 );

    Try it out and tell us if it works well for you.

    We will be attentive to your response.

    Have a nice day!

    Thread Starter kastriotsula

    (@kastriotsula)

    Hello @juaancmendez I have this error as output:

    Fatal error: Uncaught Error: Function name must be a string in /home/skimdis1/skimcorner.it/wp-content/themes/aora-child/functions.php:149 Stack trace: #0 /home/skimdis1/skimcorner.it/wp-includes/class-wp-hook.php(303): filter_category_link('https://skimcor...', 160) #1 /home/skimdis1/skimcorner.it/wp-includes/plugin.php(189): WP_Hook->apply_filters('https://skimcor...', Array) #2 /home/skimdis1/skimcorner.it/wp-includes/taxonomy.php(4547): apply_filters('category_link', 'https://skimcor...', 160) #3 /home/skimdis1/skimcorner.it/wp-includes/class-walker-category.php(108): get_term_link(Object(WP_Term)) #4 /home/skimdis1/skimcorner.it/wp-includes/class-wp-walker.php(144): Walker_Category->start_el('', Object(WP_Term), 0, Array) #5 /home/skimdis1/skimcorner.it/wp-includes/class-wp-walker.php(202): Walker->display_element(Object(WP_Term), Array, 1, 0, Array, '') #6 /home/skimdis1/skimcorner.it/wp-includes/category-template.php(1107): Walker->walk(Array, -1, Array) #7 /home/skimdis1/skimcorner.it/wp-includes/category-template in /home/skimdis1/skimcorner.it/wp-content/themes/aora-child/functions.php on line 149

    function filter_category_link( $termlink, $term_term_id ) { 
        $termlink = home_url('/blog/'. $get_term( $term_term_id )->name .'/');
        return $termlink; 
    }; 
             
    add_filter( 'category_link', 'filter_category_link', 10, 2 );

    This is the line 149

    $termlink = home_url('/blog/'. $get_term( $term_term_id )->name .'/');

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi there,
    thanks for your reply.

    Sorry, we made a mistake with the code, try this please:

    function yith_filter_category_link( $termlink, $term_id ) {
        $termlink = home_url('/blog/'. get_term( $term_id )->name . '/');
        return $termlink; 
    }; 
             
    add_filter( 'category_link', 'yith_filter_category_link', 10, 2 );

    Tell us any news, please.

    Best regards.

    Thread Starter kastriotsula

    (@kastriotsula)

    Thank you for your reply!

    I see that I have a 404 but the structure is correct like this:

    https://skimcorner.it/blog/Skimboard/

    But on a few categories the system redirect me on the post blog for example

    With this category here:

    https://skimcorner.it/blog/Skateboard/

    I have been redirect in the blog post with this url:

    https://skimcorner.it/blog/skateboard-o-longboard-ecco-le-principali-differenze/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Remove base prefix from url for category brands’ is closed to new replies.