PHP coding for Google Search

Posted on 2011-09-05
Medium Priority
Last Modified: 2012-05-12

I would like to add a google custom search for the site http://secureinfo.info/ 
I want the search bar to appear in the right corner of the header section.

Attached is the current header.php file. If you need any other php file, please let me know.

Any help is appreciated as i do not know much about any php coding. I have the google code for the search bar and the search result page.

Question by:ujitnos
  • 4
  • 3

Accepted Solution

ropenner earned 1500 total points
ID: 36482890
line 31 and 32 are...

<body <?php body_class(); ?>>


insert your code for the google search inbetween these two.  If it is PHP code then it is enclosed in <php ?> tags otherwise if it is HTML only then plop it in there.

To position it to the far top right you can use a table to contain it and absolute HTML positioning.  A sample of how it may appear in the header.php file is below... starting at line 31

<body <?php body_class(); ?>>
      <TABLE style="position:absolute; top:0px;right:5px">your stuff</TABLE>

code below is a working example placed right after the body tag



   <TABLE style="position:absolute; top:0px;right:5px">



   			<SCRIPT language=javascript>

   				function addSite() {

   					var query = document.getElementById('q').value;


   					return false;



   			<FORM onsubmit="javacript:return addSite();">

		   		<INPUT type=text size=20 id=q name=q>







Open in new window

LVL 10

Author Comment

ID: 36483228
Ok, please review the page. I need to move it a bit down, in line with the title "Secure Info" How to?

I still not able to produce search results, but i will look into that.

This is what i inserted:-

<TABLE style="position:absolute; right:150px">
<form action="http://secureinfo.info/search-results" id="cse-search-box">
    <input type="hidden" name="cx" value="partner-pub-80feferf823723193:gtfedsgzg3104" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="55" />
    <input type="submit" name="sa" value="Search" />
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
LVL 10

Author Comment

ID: 36483338
Hi, I also noticed that it is not aligned properly in Firefox
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.


Expert Comment

ID: 36483378
The form needs to be within a table row and data cell

you need to put

  ... your stuff

  otherwise it pushes the content outside of the table ... then you can play with the alignment

LVL 10

Author Comment

ID: 36483466
Ok, thanks, got that right. Now how do i move it a bit down ?

Assisted Solution

ropenner earned 1500 total points
ID: 36485253
add to your table's style how far from the TOP of the screen you want it to appear.  It is in the original post's code as well

style="position:absolute; top:20px; right:50px"
LVL 10

Author Closing Comment

ID: 36500614

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question