1

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?

5
  • 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? Commented Aug 1, 2014 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. Commented Aug 2, 2014 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. Commented Aug 2, 2014 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. Commented Aug 3, 2014 at 14:57
  • Then I guess Milos's answer is the way to go Commented Aug 3, 2014 at 16:36

1 Answer 1

1

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' );
2
  • How would that work if there are multiple query strings? Maybe a custom field could be utilized. Commented Aug 2, 2014 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. Commented Aug 3, 2014 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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