WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With add_query_arg() it is nice to add additional parameters to an URL and it is also easy to create a rewrite rule. So far so good. But the problem is the URL replacement done by wordpress.

When I have an URL, like:


and I type this URL into the address line of the browser with activated permalinks. This link will become to:


BUT: what I would like to get is:


Finally, I would like to use code like:

<a href="<?php add_query_arg( 'myvar', 'test', get_permalink() ) ?>"> .... </a>

which would result in:


How can this be achieved? I have spent hours in reading documents and I couldn't found a solution.

share|improve this question
I'd like to know how this is done. +1 to the question. – henrywright Dec 27 '13 at 21:04

Just faced the same situation and stumbled upon this question while googling.

It seems like this isn't possible. Core itself just appends strings to the URL if pretty permalinks are enabled, see https://core.trac.wordpress.org/browser/tags/3.9.1/src/wp-includes/link-template.php#L571

For anyone interested in this: You can do something like this in your code:

if ( '' != get_option('permalink_structure') ) {
    // using pretty permalinks, append to url
    $read = user_trailingslashit( get_permalink() . 'test' ); // www.example.com/pagename/test
  } else {
    $read = add_query_arg( 'test', '', get_permalink() ); // www.example.com/pagename/?test

This solution is also was also recommended by Jon Cave in a comment on the official make blog: https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/#comment-686

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.