I need to add query string to all pages including homepage.after user logged in. as example after user logged in homepage url need to look like domain.com?aff=1234567 and other links also modify with custom query string such as page domain.com?p=1&aff=1234567

anyone has idea how to do this or how can i use wp_redirect for this

  • Can I ask what you're trying to do? Might be an easier way. – Jacob Peattie Dec 7 '17 at 2:57
  • I need to add custom variable to address bar like Original URL:server/?id=10 Resulting URL: server/?id=10&enabled=true – srinath madusanka Dec 7 '17 at 3:01
  • @srinathmadusanka I agree with Jacob, it's clear what you're trying to do, but it's not clear why? What problem does this solve? Is there a reason you can't store this info in cookies or user meta? – Tom J Nowell Dec 7 '17 at 3:01
  • To do what though? What are you using the query arguments for? Do they need to be in the URL? Why not store values with user and retrieve with get_user_meta(), or store in a session variable? Why do they have to be in the URL. – Jacob Peattie Dec 7 '17 at 3:03
  • it need to save to contactform 7 via get – srinath madusanka Dec 7 '17 at 3:56

add following code to functions.php,

add_action('wp_head', 'your_function');
function your_function(){
    if ( is_user_logged_in() ) {
        $genre_url = add_query_arg('aff', '1234567', get_permalink());

Hope this will help you. for more information,

  • This isn't going to do anything. It's just setting the value of $genre_url to the permalink of the current post with a query arg, but the variable isn't used anywhere, and certainly isn't being added to the url. Also, get_permalink() will only be correct for single posts/pages. Category and date archives won't work because get_permalink doesn't get their URLs. you'd just get the URL to the first post in the archive. – Jacob Peattie Dec 7 '17 at 4:58

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.