Remove custom taxonomy base from URL

Depending on how you are registering your custom post types, you can simply set the rewrite rules for it like so: $args = array( ‘description’ => ‘Photograph Post Type’, ‘label’ => __(‘Photographs’), ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘photograph’), ); register_post_type( ‘photograph’ , $args ); If (for some bizarre reason) you don’t have … Read more

RewriteRule accepts numbers but not letters in tag

Leave .htaccess alone. You can use WordPress rewrite API for this. add_action( ‘init’, function(){ return add_rewrite_rule( ‘subdir/([^/]+)/?$’, // ([^/]+) takes alphanumeric, while ([0-9]+) accepts digits ‘index.php?pagename=subdir&website=$matches[1]’, ‘top’ ); }); add_filter(‘query_vars’, function($v){ return array_merge(array(‘website’),$v); }); First make sure subdir is a valid page slug, in this example. After you save that code to your child theme’s … Read more

How to catch Rewrite rules then display a specific post?

It appear, like @milo also said, that the correct way to doing this is by using the “parse_request” action that stand before the “pre_get_posts” action (see https://codex.wordpress.org/Plugin_API/Action_Reference). The complete solution I came with : add_action(‘init’, function () { $refs_slug = getCustomRefTermsSlug(); // this will return an array of all the terms slug existing in the … Read more

Static variable and add_rewrite_rule?

You can’t add arbitrary query variables to the rewrite rules, there’s a whitelist of allowed variables. To add a query variable, use query_vars filter, e.g. this filter adds my-api as a valid query variable: function wpd_query_vars( $query_vars ){ $query_vars[] = ‘my-api’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_query_vars’ ); But that just gets you the query … Read more

Url Rewriting a dynamic wordpress page

thanks for you reply, So after much digging, it’s working : function myplugin_rewrite_tag_rule() { add_rewrite_tag( ‘%symbol%’, ‘([a-zA-Z0-9_]+)’ ); add_rewrite_rule( ‘^crypto-monnaies/([a-zA-Z0-9_]+)/?$’, ‘index.php? pagename=showcoin&symbol=$matches[1]’,’top’ ); } add_action(‘init’, ‘myplugin_rewrite_tag_rule’); function add_query_vars( $query_vars ) { $query_vars[] = ‘symbol’; return $query_vars; } add_filter( ‘query_vars’, ‘add_query_vars’ ); Please note that if you dynamic page is a second level page, you have … Read more

WordPress custom post type permalink: website.com/post-name/post-id

product/([0-9]+)?$ translates to product/ followed by any number or nothing (and nothing more, not even a trailing slash). This doesn’t sound like the thing you want to achieve. Instead, try the following function wpse33551_rewrites_init(){ add_rewrite_rule( ‘^([^/]+)/([0-9]+)/?$’, ‘index.php?post_type=artikelen&p=$matches[2]’, ‘top’ ); } which translates to: ^ start of the string (ie, there is nothing else in front) … Read more