top of page

Change slug of [Custom Taxonomy] on fronted

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • May 28, 2020
  • 1 min read

This is very curious code as you we end up creating taxonomies like "product-cat" or "product_cat" so following code come to rescue earlier the URL was


http://34.230.181.212/sr/product_cat/flans/

after using code above it became


http://34.230.181.212/sr/product-category/flans/



function space_change_custom_taxonomy_slug_args( $taxonomy, $object_type, $args ){
        if( 'product_cat' == $taxonomy ){ 
            remove_action( current_action(), __FUNCTION__ );
            $args['rewrite'] = array( 'slug' => 'product-category' );
        register_taxonomy( $taxonomy, $object_type, $args );
        }
}
add_action( 'registered_taxonomy', 'space_change_custom_taxonomy_slug_args', 10, 3 );



Recent Posts

See All
Hide Upcoming Events

Hiding Upcoming Events can be relatively useful when you are using ACF fields to show Dates for an an Event The Following Snippet is an...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page