Custom post type slug localization

First, you should have to register your custom post type with a generic, language-independent slug because the slug in register_post_type is not meant to be dynamic. and then modify rewrite rule try this snippet function register_custom_post_type_services() { $labels = array( ‘name’ => _x(‘Services’, ‘Post Type General Name’, ‘text_domain’), ‘singular_name’ => _x(‘Service’, ‘Post Type Singular Name’, … Read more

How to get a custom taxonomy slug in body classes

To add the custom taxonomy slug to the body classes of your WordPress site, you can use the body_class filter along with your custom code. Below is your example of how you can achieve this: function themeprefix_add_taxonomy_class($classes) { global $post; if (is_page()) { $taxonomy = ‘page_section’; $terms = get_the_terms($post->ID, $taxonomy); if ($terms && !is_wp_error($terms)) { … Read more

Right Permalink for Custom Post Type with number slug

You need to write a rewrite URL for the galley, please see the below code and paste into your active theme functions.php file function gallery_custom_rewrite_rule() { add_rewrite_tag(‘%gallery_id%’, ‘([^&]+)’); // Rule to handle numeric slugs in a gallery post type add_rewrite_rule( ‘^gallery/(.+)/([0-9]+)/?$’, ‘index.php?post_type=gallery&gallery_id=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘gallery_custom_rewrite_rule’, 10, 0); function gallery_query_vars($query_vars) { $query_vars[] = ‘gallery_id’; … Read more

category id (term_id) in url instead of slug

Try this. Here is the full code that you can add to your functions.php file: // Add custom rewrite rules function add_custom_rewrite_rules() { add_rewrite_rule( ‘^category/([0-9]+)/?$’, ‘index.php?term_id=$matches[1]’, ‘top’ ); flush_rewrite_rules(false); // Temporarily set this to true to flush rules, then set back to false } add_action(‘init’, ‘add_custom_rewrite_rules’); // Add term_id to query vars function add_query_vars($vars) { … Read more