• Resolved terryally

    (@terryally)


    I would like to use the following code on one of my pages. I hard-coded it but the file is not displaying. How do I achieve this?

    // Set up the airport variables
    		$toairport = $result['destination_addresses'][0];
    		$fromairport= $result['origin_addresses'][0];
    
    			/**
    			 * Check if the location is an airport.
    			 *
    			 * @param string $location
    			 * @return bool
    			 */
    			function isAirport($location)
    			{
    			    $airportList = ['Heathrow', 'Gatwick', 'London Luton', 'London City Airport'];
    			    foreach ($airportList as $airport) {
    			        if (strpos($location, $airport) !== false) {
    			            return true;
    			        }
    			    }
    
    			    return false;
    			}
    if (isAirport($toairport) || isAirport($fromairport)) { ?>
        <div class="airport-transfer">
        	<p>We see that your journey involves a London airport transfer.</p>
        	<p>On the meter, the cost can range from <b>
        		<?php
        		if ($Distance <= intval(1454)) {
        			echo $DayMinDistanceCost . " </b>to<b> " .$FestiveMinDistanceCost;
        		} else {
        			echo $DayCost . " </b>to<b> " .$FestiveCost;
        		} ?>
        	</b>or higher, depending on traffic.</p>
        	<p>We may be able to offer you a competitive flat rate. Please contact us on <b>01252-83-40-50</b> and ask for a London Airport Transfer rate.</p>
        </div>
        <div class="another-quote">Get another <a href="<?php echo $_SERVER['PHP_SELF'];?>">quote</a></div>
    <?php }
Viewing 3 replies - 1 through 3 (of 3 total)
  • lisa

    (@contentiskey)

    1-you could add code to functions.php file in your child theme
    2-you could create a simple plugin just to manage this code

    (you MIGHT need to use some more conditional tags so it only applies to specific pages)

    Thread Starter terryally

    (@terryally)

    I should have mentioned … this is the first time I am dabbling with WP, so I don’t know how to add/call from functions.php — the documentation is totally clear to me and I have no idea how to create a plugin … would appreciate some help to explain either …

    Thread Starter terryally

    (@terryally)

    Mystery solved.
    There is nothing wrong with the code.
    It’s the server running PHP 5.2.
    Once I changed to 5.6, all’s okay.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to include a custom function file’ is closed to new replies.