You can add a rewrite rule to map to one of those pages with something like this:
add_action( 'init', function() {
add_rewrite_rule( 'myparamname/([a-z0-9-]+)[/]?$', 'index.php?myparamname=$matches[1]', 'top' );
} );
The first parameter of add_rewrite_rule
is a regular expression to match a URL. The second parameter is an index.php
non-pretty permalink URL, the URL parameters map directly into WP_Query
arguments.
So if we take your first page as an example collections/collection/example
:
add_action( 'init', function() {
add_rewrite_rule( 'collections/collection/([a-z0-9-]+)[/]?$', 'index.php?name=collection&collection_parameter=$matches[1]', 'top' );
} );
name=collection
tells WordPress we want the page with the slug collection
, and collection_parameter
is how we’re passing the final parts value.
We then need to allow the use of collection_parameter
, and adjust the page template to use it instead of $_GET
To grab the value from your page template:
$collection = get_query_var( 'collection_parameter' );
To whitelist the parameter we need to add it to the whitelist:
/**
* Register custom query vars
*
* @param array $vars The array of available query variables
*
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
*/
function myplugin_register_query_vars( $vars ) {
$vars[] = 'collection_parameter';
return $vars;
}
add_filter( 'query_vars', 'myplugin_register_query_vars' );
Don’t forget to flush rewrite rules, and you can extend this for the other two pages.