X
X

Change The WordPress Post Template Via URL Parameter

Link

Used in Notes for the iframe on the front page.

How To Serve Up A Different Template

First we need to let WordPress know about the URL parameter so we can detect it later. We do this by adding the following code to your theme’s functions.php file:

function sjc_add_query_vars($vars) {
return array(‘template’) + $vars;
}
add_filter(‘query_vars’, ‘sjc_add_query_vars’);

Next, we check for the existence of the URL parameter / query_var, by adding the following code to your theme’s functions.php file (below the code given above):

function sjc_template($template) {
	global $wp;
	if ($wp->query_vars[‘template’]==’basic’) {
		return dirname( __FILE__ ) . ‘/single-basic.php’;
	}
	else {
		return $template;
	}
}
add_filter(‘single_template’, ‘sjc_template’);