07 May 2007

Future-proof your custom WordPress Page

Here’s a silly way to create a future-proof custom WordPress Page. I usually depend on custom Page Template rather than Default Page Template when creating a Page. This is because some of the Pages that I created involve some extra PHP codes.

For those that didn’t know, WordPress doesn’t allows <?php ?> tags inside the content of your posts or pages unless with a help from a plugin like PHP-Exec. Basically that particular plugin will do the same thing but my method sort of hard-coded and future-proof. Unfortunately, the downside of this method is that the content of that page isn’t stored inside the WordPress database.

Add the following lines to your WordPress Theme’s template functions.php file (For example, functions.php file for a Theme named “default” would probably reside in the directory wp-content/themes/default/functions.php) or create it as a Plugin by filling the additional Standard Plugin Information:

<?php
function custom_page($content) {
	if ( is_page('PAGE') ) {
		echo "your PHP stuff here....";
	} else {
		return $content;
	}	
}

add_filter('the_content', 'custom_page');
?>

Do assign and change PAGE with any supported parameter for is_page() Conditional Tag. Read WordPress Codex A PAGE Page for more information.