functions – How to rewrite the custom url in wordpress?

Question

I have tried to rewrite the url from
http://example.com/club/?state=AL

to
http://example.com/club/AL

Added query vars and rewrite url in functions.php

add_filter('query_vars', 'my_query_vars', 10, 1);

function my_query_vars($vars) {
    $vars[] = 'club'; 
    return $vars;
}


function custom_rewrite_basic() 
{
    add_rewrite_tag("%club%", "([a-z0-9\-_]+)");
       add_rewrite_rule('^club/([a-z0-9\-_]+)/?$', 'index.php?pagename=club&State=$matches[1]', 'top');

}
add_action('init', 'custom_rewrite_basic');

0
Mike 1 year 2022-02-11T13:52:01-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse