Affiliates WordPress Multisite

I have a pricing table with signup buttons on the main site. When the button is clicked it brings you to another site where the membership plugin and Affiliates plugin will be installed. Is there a way to add code to the signup button link so a user coming in from the main site will be tracked through to the member site?

One of the buttons has a url like: is there a way to add some additional characters to the url that will trigger the tracking on the Member/Affiliate site?

something like with the ? being the variable?

  • Adam Czajczyk

    Hi Trevor

    I hope you're well today!

    I assume that the "" is on a main site of your multisite, right? If so, then yes, you just need to add a referral part to the URL (e.g. to the URL of the button on any other site) exactly the way you suggested, e.g:

    This identifies which affiliate send the traffic to that page. You can put such URL on any page/website.

    There's also a "debug" mode that can be enabled in Affiliates plugin which will let you test that. Once enabled, it displays info about referring affiliate on front end.

    Best regards,

  • Trevor

    Hi Adam,

    Thanks for the reply. Just to clarify as I think their may be some confusion with the Title of this post.

    My main site is a single site WordPress install and has a pricing chart for our hosting plans. At the bottom of each plan column is a Sign Up button. When you click a Sign Up button, you are taken to another site (that happens to be a Multisite install) where the Memberships 2 and Affiliates plugins are installed.

    If an Affiliate directs traffic to our main site and a visitor clicks on a Sign Up button, they are directed to where they would signup and pay for their Membership.

    If the Sign Up button link on the main site used a url like: that will trigger the Affiliates plugin to track that visitor and assign the commission to the appropriate Affiliate?

    If so, then the Affiliate could just send them to the main site, where the visitor could browse our site and when they click on the Sign Up button they would be tracked?

    Where I'm concerned is, there is no plugin or code on the main site that would initiate the tracking once they landed on the site, so I'm not sure how clicking on the Sign Up button would know where the visitor came in from.

    Hope this makes sense. Please let me know if you need clarification.


  • Adam Czajczyk

    Hi Trevor

    Thanks for additional explanation!

    It seems I didn't got the whole picture initially, it's much more clear now :slight_smile: And it actually changes things quite a bit. Basically, this

    If the Sign Up button link on the main site used a url like: that will trigger the Affiliates plugin to track that visitor and assign the commission to the appropriate Affiliate?

    should work but, as you already rightfully noticed, the problem is that the "button must know the ref code first", so to say. The "" site, where the button is, is a totally separate site so there's no tracking and, of course, that tracking part of an URL must by "dynamic" in that sense, that it cannot be "hard-coded" in button URL. Otherwise it would always track the same affiliate.

    So, the only option here would be to "intercept" the affiliate "reflink". That could actually be done and I think with a little bit of a custom code it should do a trick. The "reflink" always has the same structure - it's based on the "ref" URL parameter so to catch it and be able to use it on the site, you'd need to add this code to the "functions.php" file of the current theme of the "" site:

    function wpmu_aff_reflink_query_var_add($vars) {
      $vars[] .= 'ref';
      return $vars;
    add_filter( 'query_vars', 'wpmu_aff_reflink_query_var_add' );
    # intercept reflink
    function wpmu_intercept_aff_reflink() {
    	// read "ref" value from URL
    	$affiliate = get_query_var( 'ref' );
    	// if it exist return entire reflink
    	if ( !empty($affiliate) ) {
    		return '?ref=' . $affiliate;

    Once you got that, you can actually dynamically "build" your sign up button but that would have to be done directly on a page template level. What I mean, is that instead of adding the button directly via a WP editor or some page builder, you would actually need to create and/or edit a code in a page template. Something like this would work:

    <p class="signup-button">
    <a href="<?php echo wpmu_intercept_aff_reflink();?>">SIGN UP</a>

    This is, of course, just an example HTML markup but the clue is that short PHP part in it that actually adds up the "reflink" part to the button URL.

    That should do the trick as if any site directs a visitor to

    the "Sign UP" button URL would automatically become

    The downside is that the "" site wouldn't use cookie to store affiliate ID but that would happen anyway on the "end point" (the However, the code that I gave could be expanded to store "reflink" or even give additional stats but that's a bit too far into custom coding and would be outside the scope of this forum, I'm afraid.

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.