How can I append the page title variable onto a url

46 Views Asked by At

In Wordpress, I need to append the page title variable ($page) into a link on an elementor button

so link in elementor button is https://test.com/apply

And I want to track which page the click has come from using UTM

e.g. https://test.com/apply?utm_source=homepage

or https://test.com/apply?utm_source=FAQ

so I need to have something like : https://test.com/apply?utm_source=$page

Is this possible?

I've tried a few different ways, but nothing seems to work.

1

There are 1 best solutions below

0
SavPhill On

You can manipulate strings and concatenate variables.

Example:

    <?php
// Your BAse URL
$baseUrl = "https://test.com/";

// page title variable
$title = "MyPageTitle";

// Append the title variable to the URL
$finalUrl = $baseUrl . "?title=" . urlencode($title);

// Output the final URL
echo $finalUrl;
?>

Result in this case should be:

https://test.com/?title=MyPageTitle