简体   繁体   中英

Passing dynamic parameters from URL to external links in my page

First of all keep in mind that I have totally NO programming skills. I just have a blog with wordpress, where I promote some affiliate offers making full reviews or top-list (eg. top 5 best dating sites)

Now I want to promote one of these articles with google ads.

So let's say that the final URL that I'll use in Google Ads campaign will be: mysite.com/?source={keyword} and someone finds my article searching "dating" on google, clicking it. The final URL the user will visit will be mysite.com/?source=dating ... right?

Now the user will click one of the links I promote, that are EXTERNAL links of course.

What I need is that dynamic parameter to be "catched" from the URL and put in the links. So automatically all links will be externalsite.com/?source={keyword}

Is that possibile in some easy way? Thanks!

I can't imagine google would love you doing this, so you may want to review the terms of service, but that aside, I don't know of any plugins geared towards that but in theory it shouldn't be too difficult and would be worth searching if anything exists. I assume you are willing to try your hand at programming since you asked this on stack overflow, so if you wanted to make your own plugin for this you'd probably want to use the template_redirect action hook to then see if a get request is set.
This is crude and quick example but something along the lines of:

add_action('template_redirect', function(){
  $keyword = 'dating';
  if(isset($_GET['source']) && ($_GET['source'] == $keyword)){
    // Redirect Somewhere else
    wp_redirect("externalsite.com/?source={$keyword}");
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM