I'm currently working on a WordPress website where I want to make 1 custom landing page but pass 3 parameters in the URL and then use those parameters in the page itself.
Example
http://website.co.uk/landing/daewoo/boilers/in/kent
http://website.co.uk/landing/bosch/airconditioning/in/london
broken into params that is
http://website.co.uk/{customPage}/{manufacturer}/{product}/in/{location}
The content will be the same on every page that is shown but I then need to use the 3 parameters passed in the page.
For example I want to make the title something like "Daewoo Boilers in Kent" and again use those parameters in the page itself like this:
Hadene are one of the largest independent commercial {product} specialists in {location}. We are able to install, service and maintain a wide variety of {manufacturer} {product}. We work with all fuel types, be it gas, LPG, oil or electric. You can count on Hadene in {location} to work with you to create a solution to suit your needs. Our servicing and maintenance covers planned, preventative and remedial work, and our service contracts will cover emergency repairs, breakdown cover and emergency call outs. No {manufacturer} {product} is too big or too small for us to look after for you.
We cover a variety of {location} commercial establishments;
For all your {manufacturer} {product} needs in {location} get a quote now
I'm competent in PHP and have full server access but I'm just not sure how to do this in WordPress and have never made a custom page. I'm not even sure if I simply need a plugin to be able to do this?
I'm a quick learner but need examples to learn by please, not just pointers as I don't understand that way :(
To then get this to be picked up by the search engines I intend to either make the links in a page to be spidered or custom add them to the robots file
Thanks, Neil
function landingMainBody_func( $atts ){
global $wp;
$route = add_query_arg( array(), $wp->request );
$manufacturer = "## NO MANUFACTURER ##";
$product = "## NO PRODUCT ##";
$location = "## NO LOCATION ##";
$result = explode("/", $route);
echo"<br/>";
echo "## route:".$route."<br/>";
echo "## result[0]:".$result[0]."<br/>";
echo "## result[1]:".$result[1]."<br/>";
echo "## result[2]:".$result[2]."<br/>";
echo "## result[3]:".$result[3]."<br/>";
echo "## result[4]:".$result[4]."<br/>";
if ($result['1'] && $result['2'] && $result['4']){
$manufacturer = $result[1];
$product = $result[2];
$location = $result[4];
}
$result = <<<END
Hadene are one of the largest independent commercial $product specialists in $location. We are able to install, service and maintain a wide variety of $manufacturer $product. We work with all fuel types, be it gas, LPG, oil or electric. You can count on Hadene in $location to work with you to create a solution to suit your needs. Our servicing and maintenance covers planned, preventative and remedial work, and our service contracts will cover emergency repairs, breakdown cover and emergency call outs. No $manufacturer $product is too big or too small for us to look after for you
We cover a variety of {location} commercial establishments;
<ul>
<li>Schools, colleges and universities</li>
<li>Pubs, bars, nightclubs, hotels and restaurants</li>
<li>Council offices, fire stations and police stations</li>
<li>Swimming pools, leisure centres and gyms</li>
<li>Office blocks and commercial premises</li>
<li>Garden centres, shops, retail stores and car dealerships</li>
<li>Church buildings</li>
<li>Hospitals and care homes</li>
</ul>
For all your $manufacturer $product needs in $location get a quote now
END;
return $result;
}
add_shortcode( 'landingMainBody', 'landingMainBody_func' );
function add_query_vars($aVars) {
$aVars[] = "h_manufacturer,h_product,h_in,h_location";
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('landing/([^/]+)/?$' => 'index.php?pagename=landing&h_manufacturer=$matches[1]&h_product=$matches[2]&h_in=$matches[3]&h_location=$matches[4]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
[^/]+
function add_rewrite_rules($aRules) {
$aNewRules = array('boilers/([^/]+/[^/]+)/?$' => 'index.php?pagename=boilers');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
function landingBoilerMainBody_func(){
global $wp;
$route = add_query_arg( array(), $wp->request );
$manufacturer = "";
$location = "";
$result = explode("/", $route);
// match the boilers page or redirect to home
if ($result['0'] == 'boilers'){
if ($result['1'] && $result['2'] ){
// sanitise and populate results
$manufacturer = ucfirst($result[1]);
$location = ucfirst($result[2]);
} else {
// redirect to home
//wp_redirect(index.php);
}
}
$result = <<<END
<h1>For all your $manufacturer boiler needs in $location get a quote now</h1>
We are one of the largest independent commercial boiler specialists in $location. We are able to install, service and maintain a wide variety of $manufacturer boilers. We work with all fuel types, be it gas, LPG, oil or electric. You can count on us in $location to work with you to create a solution to suit your needs. Our servicing and maintenance covers planned, preventative and remedial work, and our service contracts will cover emergency repairs, breakdown cover and emergency call outs. No $manufacturer boiler is too big or too small for us to look after for you
<br/><br/>
For all your $manufacturer boiler needs in $location get a quote now
END;
return $result;
}
add_shortcode( 'landingBoilerMainBody', 'landingBoilerMainBody_func' );
In your functions.php page, create shortcode https://codex.wordpress.org/Shortcode_API
Open in new window
If you put the shortcode [foobar] on your page, where you place that shortcode will output, "foo and bar".Now try using the code below. You should see that if you are on page https://yourdomain.com/testing, the return is "testing"
Open in new window
You can see if you are on the top level, and the page is, 'test" that the output will be, 'test" If you are on https://yourdomain.com/testing/test, the output will be "testing/test".
Can you see from there you can explode that https://www.php.net/manual/en/function.explode.php and end up with an array?
Using your example, http://website.co.uk/{customPage}/{manufacturer}/{product}/in/{location}
array[0] would be customPage
array[1] would be manufacturer
array[2] would be product
array[3] would be in
array[4] would be location
You can add on to the output example using the data. Make sure to account for missing data though.