Print a value in wordpress within a page

hello i am trying to print a value from the URL within a page on a WordPress site

i have edited the header.php and entered the following code

Read More
<?php
$town = rawurldecode( $_GET['town'] ); ?>

on the page i want to print the value i added

<?php print $town ?>

I have tried a few plugins that ment to allow php in the pages but i get errors

the url looks like this

website.co.uk/page/?town=abc

The results i was trying for was to use the PHP tag when i needed it within the page

for example

Hello i live in <?php print $town ?>, would you like to 
come see the football in <?php print $town ?>?.

Did you know that <?php print $town ?> is not that far?

Related posts

Leave a Reply

2 comments

  1. Change

    $town = rawurldecode( $_GET['town'] );

    to

    if(isset($_GET['town'])) { $town = rawurldecode( $_GET['town'] ); } else { $town = "No town"; }

    And change

    <?php print $town ?>

    to

    <?php echo $town; ?>

    Maybe this will work, please let us know the result.