woocommerce - How to remove custom post type slug & taxonomy-base from URL in WordPress -
i using woo-commerce
i have bellow code remove post type "product" slug url , works fine.
product url = http://example.com/product/product-name/ to
product url = http://example.com/product-name/
function df_custom_post_type_link( $post_link, $id = 0 ) { $post = get_post($id); if ( is_wp_error($post) || 'product' != $post->post_type || empty($post->post_name) ) return $post_link; return home_url(user_trailingslashit( "$post->post_name" )); } add_filter( 'post_type_link', 'df_custom_post_type_link' , 10, 2 ); function df_custom_rewrite_rule() { add_rewrite_rule('(.*?)$', 'index.php?product=$matches[1]', 'top'); } add_action('init', 'df_custom_rewrite_rule');
now how remove taxonomy-base url
example:
product category url = http://example.com/product-category/product-category-name/ product category url = http://example.com/product-category-name/
this old question actually.. , question simple answered: woocommerce says isn't possible. quote: "unfortunately not possible due way wordpress resolves urls."
but did research , there possibilities fix plugins, or maybe handy coding yourself. these plugins designed remove custom taxonomy , posttype wc urls. don't know if im allowed share link you, answer sure. oh, , payed plugin... forgot mention. http://www.perfectseourl.com
Comments
Post a Comment