Is it possible to prevent WP from stripping out certain characters when customizing a URL? For example, affiliate ids usually have something like ?id=something. Customizing a content's slug with that results in the ? being converted to a \. Any way to keep WP from rewriting the URL?

  • I don't understand the motivation. Why do you care if the URL of the post is example.com>id=45, how does it serve identifying the affiliate? – Mark Kaplun Aug 1 '14 at 21:44
  • It's how affiliate systems work - part of the url identifies the referrer, allowing them to earn a commission on a sale. An example url would be: domain.com/product?id=something I'm trying to figure out a way to hardcode an id to a URL when the norm for WordPress slugs is to strip out characters. – Arp Laszlo Aug 2 '14 at 11:36
  • but the id of the affiliate should be in the referring link, it doesn't have to be part of the slug. One will use example.com/test?id=1 and the other example.com/test?id=2 but the slug itself can be "test", there is no need for a different slug for each affiliate. – Mark Kaplun Aug 2 '14 at 16:49
  • I'm trying to figure out a way to fix a slug (and thus a specific product) with a single, specific affiliate - hence my question here. Sorry if I was not clear about that. – Arp Laszlo Aug 3 '14 at 14:57
  • Then I guess Milos's answer is the way to go – Mark Kaplun Aug 3 '14 at 16:36

If you need to add query string arguments to permalinks, use the_permalink filter:

function append_query_string( $url ) {
    return add_query_arg( 'id', 'something', $url );
add_filter( 'the_permalink', 'append_query_string' );
| improve this answer | |
  • How would that work if there are multiple query strings? Maybe a custom field could be utilized. – Arp Laszlo Aug 2 '14 at 11:35
  • There must be a way to append the contents of a custom field to slug, no? That might be a good way to do it. – Arp Laszlo Aug 3 '14 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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