WP-Mix

A fresh mix of code snippets and tutorials

WordPress template_redirect Example

Quick code snippet showing basic use of the WordPress template_redirect action hook. This is provided as a quick copy/paste reference for WordPress developers. This hook is useful for customizing any functionality requiring full query information.

function shapeSpace_template_redirect() {
	
	if (is_page('about')) {
		
		// die('This is the About Page');
		
	}
	
}
add_action('template_redirect', 'shapeSpace_template_redirect');

Add this code via plugin or theme functions.php. You can customize the conditional logic or whatever you need to do. Learn more about template_redirect at the WordPress Codex.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress