• Resolved atifattari

    (@atifattari)


    Hi,

    I want to add woocommerce sku at the end of product url and also limit the slug words to 5 words and i use this code but when i add bigger title it limit it to 5 words but it did not add the sku at the end. I also tried regenerate option in tools.

    function pm_limit_slugs_length($uri) {
    $max_words = 5; // If any part of URI contains more than 5 words, the slug will be limited to first 5 words
    $new_title = ”;
    $slugs = explode(‘/’, $uri);

    for($i=0, $count = count($slugs); $i < $count; $i++) {
    $slug = $slugs[$i];
    $words = explode(‘-‘, $slug);

    $new_title .= “/”;
    if(count($words) > $max_words) {
    $new_title .= implode(“-“, array_slice($words, 0, $max_words));
    } else {
    $new_title .= $slug;
    }
    }

    // Remove trailing slashes
    $new_title = trim($new_title, “/”);

    return $new_title;
    }
    add_filter(‘permalink_manager_filter_default_post_uri’, ‘pm_limit_slugs_length’, 99);
    add_filter(‘permalink_manager_filter_default_term_uri’, ‘pm_limit_slugs_length’, 99);

Viewing 1 replies (of 1 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @atifattari,

    Could you try to replace:
    add_filter(‘permalink_manager_filter_default_post_uri’, ‘pm_limit_slugs_length’, 99);
    with:
    add_filter('permalink_manager_filter_default_post_slug', 'pm_limit_slugs_length', 99);

    As regards SKU, this feature is included in the paid version of plugin. If you need my assistance please send me your license key and more details directly to my email address. On this forum, I provide the support for functionalities included in free version of plugin.

    Best regards,
    Maciej

Viewing 1 replies (of 1 total)
  • The topic ‘How to add sku at the end of slug’ is closed to new replies.