• I have a Webiste running wordpress: webiste.com
    Now I want to add a custom parameter to it: website.com?custom=param1
    I want this parameter to be persistent throughout the entire WordPress navigation, meaning:
    https://www.website.com?custom=param1
    click on blog post #1
    https://www.website.com/category/blogpost1?custom=param1
    click back on homepage
    https://www.website.com?custom=param1
    click on page #2
    https://www.ebsite.com/category/page2?custom=param1
    and so on until it’s changed.

    I am pretty new to WordPress, I read a lot but I didn’t find this exact case. I tried adding add_query_vars_filter but it dosen’t make the parameter persistent throughout the blog. I would appreciate some help, articles, code snippets, plugins ??

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • YBM

    (@ybmgryzzzgmailcom)

    Hi there all,

    I am looking for the exact same thing. I have chatted to a colleague about this too and he suggested doing it server-side – i.e. adding it as a Condition/Rule to the htaccess or httd config on the server … Not entirely sure of the proper/correct way to keep this parameter throughout a users website journey. How is it done?

    Thanks in advance

    You could do something like this:

    function wprdcv_param_redirect(){
    	if( !is_admin() && !isset($_GET['CUSTOM']) ){
    		$location = "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    		$location .= "?CUSTOM=PARAM1";
    		wp_redirect( $location );
    	}
    }
    add_action('template_redirect', 'wprdcv_param_redirect');

    Just replace CUSTOM and PARAM1 in the above code and add it to your functions.php

    YBM

    (@ybmgryzzzgmailcom)

    Hi WP Gurus

    Great thanks this works quite well but not too sure of the stability and staticity of it. I’d would like to know:

    If https://www.website.com it should stay https://www.website.com (without the ‘id’ parameter)
    If https://www.website.com?id=1234 it should stay https://www.website.com?id=1234 and all other links that go on from here should have ?id 1234 at the end
    If, for another user it is https://www.website.com?id=5678 all the links that user clicks should end with ?id=5678

    Hope that makes sense?

    Thanks again

    In its current state the code will add the same id for all users.

    YBM

    (@ybmgryzzzgmailcom)

    Thanks mate. Please advise on how to make it a different unique ID per user? And if there is no ID (and parameter) than no parameter is shown in all links going ferther?

    Thanks again

    I have the same need as listed by previous member:

    1. If https://www.website.com it should stay https://www.website.com (without the ‘id’ parameter)

    2. If https://www.website.com?id=1234 it should stay https://www.website.com?id=1234 and all other links that go on from here should have ?id 1234 at the end

    The solution listed above does add a parameter to the url, however it adds it everytime. So point 1. above is not effective i.e if someone goes to https://www.abc.com, the solution suggested takes user to https://www.abc.com/id=xyz

    Can we make point 1. above happen?

    cmF

    (@chrismfrench)

    @vipulratten I’m struggling with the exact same thing!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Passing URL Parameters to all internal links. Or Persistent URL Variables’ is closed to new replies.