1
I have a plugin that manages links in Wordpress, with images and texts pretending to be related articles, all are external links. (Taboola type).
I would like to add at the end of the Links some parameters. Ex:
Link ==> othersite.com.br
I want to add now the following:
Link ==> othosite.com.br? src=urldinamicadowordpress
So I can know the origin of these clicks and which article is converting the most clicks.
If possible, still add if the click came from mobile or Desktop
Link ==> othosite.com.br? src=urldinamicadowordpress|mobile
Link ==> othosite.com.br? src=urldinamicadowordpress|desktop
Code of Redirection
add_action('init', 'count_clicks');
function count_clicks()
{
global $wpdb;
if(isset($_GET['action']) && $_GET['action'] == 'count') {
$id = $_GET['id'];
$tableName = $wpdb->prefix . 'post_related_meta';
$meta = $wpdb->get_results($wpdb->prepare("select meta_clicks, meta_link from $tableName where meta_id = %s", $id));
$meta = $meta[0];
$wpdb->update($wpdb->prefix."post_related_meta", array(
'meta_clicks' => (int)$meta->meta_clicks+1,
), array(
'meta_id' => $_GET['id']
),
array(
'%d'
)
);
$redirect = $meta->meta_link;
header("Location: $redirect");
exit;
}
}
Got it, I took a test here and it really works! Thank you very much! But in my plugin I don’t think it can be like this, for the simple reason of having a redirect. Unless you want to pass these parameters between urls. URL that counts Click and Redirect: http://meusite.com.br/? action=count&id=1&src=testeparam Directs to: meusite.com.br I wanted you to stay: meusite.com.br? src=testeparam taking this from the first url that counts clicks.
– Anderson Costa
can do if you can intercept this redirect. Put the question the code where the redirect is done I update.
– Ricardo Moraleida
Thanks Ricardo! I updated the code for you!
– Anderson Costa
I updated the reply @Andersoncosta, see if it resolves.
– Ricardo Moraleida
It Works! Ricardo Ball Show! Vlw
– Anderson Costa