1

I have my code to register my custom taxonomies.

function themename_custom_taxonomies() {
    // Coaching Method

    $coach_method = array(
        'name' => _x( 'Nieruchomość', 'taxonomy general name' ),
        'singular_name' => _x( 'Nieruchomość', 'taxonomy singular name' ),
        'search_items' =>  __( 'Szukaj nieruchomości' ),
        'all_items' => __( 'Wszystkie nieruchomości' ),
        'most_used_items' => null,
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edytuj' ), 
        'update_item' => __( 'Zapisz' ),
        'add_new_item' => __( 'Dodaj nieruchomość' ),
        'new_item_name' => __( 'Nowa nieruchomość' ),
        'menu_name' => __( 'Nieruchomości' ),
    );
    $args = array(
        'hierarchical' => true,
        'labels' => $coach_method,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'listings/?_prop=', 'with_front' => false)
    );
    register_taxonomy( 'nieruchomosc', array( 'nieruchomosc', 'ogloszenia' ), $args );
}

At this moment my taxonomy permalinks look:

https://example.com/listings/?_prop=/term-slug/

How can I change it for (without the slashes):

https://example.com/listings/?_prop=term-slug

Thank you in advance for help.

1 Answer 1

1

I found the solution...

add_filter( 'term_link', 'remove_slash_taxonomy', 10, 2 );

function remove_slash_taxonomy( $permalink, $term ) {
        if ($term->taxonomy == 'nieruchomosc') $permalink = str_replace('/'.$term->slug.'/', $term->slug, $permalink);
        return $permalink;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.