I've written a simple shortcode and using it on my gallery page. The URL for the page looks something like this:
http://mysite.dev/gallery/?view=category-name
but I want to be able to use
http://mysite.dev/gallery/category-name
When I use a URL like so, WP redirects to what seems the nearest match it can find. For example
http://mysite.dev/gallery/nature
redirects to
http://mysite/home/nature
I've tried implementing a rewrite rule:
function add_custom_rewrites()
{
remove_filter('template_redirect', 'redirect_canonical');
add_rewrite_rule('^gallery/([^/]*)/?$', 'index.php/gallery/?category=$matches[1]', 'top');
add_rewrite_tag('%category%', '(.+)');
flush_rewrite_rules();
}
add_action('init', 'add_custom_rewrites');
but the /gallery/category page always redirects to try and by some means find the nearest matching page.
Can anyone help, please?