Ecommerce Shopify WordPress Discussion

Custom permalink for post of one category

I want to customize the permalinks structure for posts in WordPress based on their categories but only posts of one category, The permalinks of the "android" posts category become like these: https://example.com/android/mypost/ and other category posts no change: https://example.com/mypost2/ I try below code but get 404: I do "Flush Permalinks" function custom_permalinks_structure($permalink, $post, $leavename) { if ($post->post_type == 'post' && has_category('android', $post)) { $permalink = home_url('/android/' . $post->post_name . '/'); } elseif ($post->post_type == 'post') { $permalink = home_url('/' . $post->post_name . '/'); } return $permalink; } add_filter('post_link', 'custom_permalinks_structure', 10, 3); add_filter('post_type_link', 'custom_permalinks_structure', 10, 3); I try the below code too : add_filter( 'post_link', 'pl_custom_permalink', 10, 3 ); function pl_custom_permalink( $permalink, $post, $leavename ) { if ( has_category( 'android', $post->ID) ) { $permalink = trailingslashit( home_url('/android/'. $post->post_name . '/' ) ); } return $permalink; } add_action('init', 'pl_custom_rewrite_rules'); function pl_custom_rewrite_rules( $wp_rewrite ) { add_rewrite_rule( '^new_slug/(.*)$', 'index.php?name=$matches[1]', 'top' ); } add_action( 'wp', function( $wp ){ if ( ! preg_match( '#^android/#', $wp->request ) && is_singular() && in_category( 'android' ) ) { wp_redirect( get_permalink() ); exit; } } );
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.