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?
1 Answer
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' );
-
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
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.