Custom wordpress page on a new URL

I liked to have the idea of having google search my site and have it displayed within my current site design, and since wordpress allows to have action hooks that allow you to interrupt the present flow of generating the wordpress outputted page.

So to have the google searched and display results within the style that I am using I first needed to create a plugin, if you create a file within your

wordpress base directory/wp-content/plugins/codingfriendsgooglesearch

within the file below within the that directory created above, (I saved this file as googlesearch.php, but it does not matter as long as it is a .php file with the plugin details at the top of the file between the /*… */ parts.

Plugin Name: Google search page
Plugin URI:
Donate link:
Description: Google search page
Version: 0.1
Author: Ian Porter
Author URI:
function get_requested_uri() {
       $requesturi = $_SERVER['REQUEST_URI'];
       if (substr($requesturi, -1)!="/") {
               $requesturi = $requesturi."/";
       preg_match_all('#[^/]+/#', $requesturi, $matches);
       $uri = $matches[0];
       return $uri;
function google_search_display() {
       $uri = get_requested_uri();
       if ($uri[0]=='googlesearch/') {
               include(TEMPLATEPATH . '/googlesearch.php');
add_action( 'template_redirect', 'google_search_display');

What basically happens is when the template_redirect is called, this is when most of the processing of the page has already been done, and we are about to display the requested page from the blog, well in this case I would like to add function call to google_search_display, which is within this same file, and what it does is to search for ‘googlesearch/’ within the first part of the URL requested e.g.

and if so display the googlesearch.php php file from within the templates directory, and here is my googlesearch.php file, and it displays the content within the div tag with cse-search-results, with the present style around the google search results.

<?php get_header(); ?>
<div id="content" class="narrowcolumn" role="main">
<div id="cse-search-results"></div>
<script type="text/javascript">
 var googleSearchIframeName = "cse-search-results";
 var googleSearchFormName = "cse-search-box";
 var googleSearchFrameWidth = 795;
 var googleSearchDomain = "";
 var googleSearchPath = "/cse";
<script type="text/javascript"
<?php get_sidebar(); ?>
<?php get_footer(); ?>

wordpress is really nice where you are able to alter the present execution process.