Last Updated: September 30, 2021
· michiels

Add query string params/arguments to any WordPress URL

I am creating a custom page template that lists items from a "genre" taxonomy as a kind of sub menu. When you click on a genre, I want the person to stay on the custom page, but pass the chosen genre as a parameter.

Great for making custom listings of events, photo albums, or other custom types of posts.


Turns out there is cool method for this. Especially if you use it in combination with the standard get_permalink() function:

    $genre_url = add_query_arg('genre', $term->slug, get_permalink());
    # Outputs for example:

This way you don't have to parse get_permalink(), see if there are already query parameters in there. You just pass in the key-value pairs of what you would like to add and you pass in the original URL as the third argument.

See for more info.

5 Responses
Add your response

There are all sorts of weird and wonderful functions like this in the WordPress Codex, thanks for pointing this one out :)

over 1 year ago ·

and how can you delete an argument from an URL?

say, I have such an UTL:

How to transform it into this: or

over 1 year ago ·

I'm avare of removequeryarg() function. It does not help in this case(

over 1 year ago ·


the removequeryarg() function only works on query parameters (so, everything behind the ?). For example, you can use removequeryarg("action", "") to get "".

If you want to change or remove the "page/3" part you should really just grab the link to the correct url or permalink. Does that make sense?

over 1 year ago ·

nope, this will not work in my case.
or I can figure out hov to make it work)

what I have is:
three custom taxonomies. Let them be color, size, and region.
initial URL is
I alter this link with addqueryarg, so it becomes

Next a user moves to page
addqueryarg will use '' if to skip second argument.
And the permalink still shows as ''

What I do now is I have several checks like if(isset($_GET['size'])) ...
This seems to be a way out for a short list of terms, but what if there are 20-30 terms?
Believe there should be a way to work with URL)

over 1 year ago ·