[Help][SEO] Custom Woocommerce Prefix on url

#56101
  • Resolved Remastered
    Rank Math free

    Hello 🙂

    I have this code which applies a custom prefix on title

    add_filter('the_title', 'l2j_c4', 10, 2 );
    function l2j_c4 ( $title, $post_id ) {
        // Returns true on a single product page.
        if ( is_product() | is_front_page() | is_product_category() ) {
            // IDs of categories that should prepend the title
            $prepend_categories = array( 267 );
    
            // get all categories via post id
            $categories = wp_get_post_terms( $post_id, 'product_cat' ); 
    
            foreach ( $categories as $category ) {          
                // Find category
                if ( in_array( $category->term_id, $prepend_categories ) ) {
                    $title = '[' . 'L2J C4'. '] ' . $title;
                }
            }
        }
    
        return $title;
    } 
    add_filter('the_title', 'l2j_c4', 10, 2 );

    Results: https://prnt.sc/sp1e3y

    I need help for that prefix to be applied to the URL too.

    How is that possible?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math today.

    Meanwhile it is not a filter offered by Rank Math, you could check the following blog post where they talk about modifying the URL just as you want: https://jasonyingling.me/dynamically-overwrite-wordpress-permalinks-with-filters/

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘[Help][SEO] Custom Woocommerce Prefix on url’ is closed to new replies.