Skip to content

Instantly share code, notes, and snippets.

@ryansnowden
Created April 22, 2015 23:05
Show Gist options
  • Save ryansnowden/a8caacfb0ed80f6a7b12 to your computer and use it in GitHub Desktop.
Save ryansnowden/a8caacfb0ed80f6a7b12 to your computer and use it in GitHub Desktop.
<?php
/**
* Load landing page template & register shortcodes from URL query
*
* @return void
*/
add_action('template_redirect', 'landing_template');
function landing_template() {
if (get_post_type() == 'landing') {
$template = get_field('template');
if (isset($template)) {
$parts = wp_parse_args($_SERVER['QUERY_STRING']);
foreach ($parts as $key => $value) {
add_shortcode($key, 'return_shortcode');
}
load_template(TEMPLATEPATH . "/single-landing-$template.php");
exit;
}
}
}
/**
* Return the value from the URL in place of a shortcode
*
* @return string Querystring
*/
function return_shortcode($atts, $content, $name) {
if (isset($name)) {
return $_GET[$name];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment