How to initialize Google Maps in the body tag? How to initialize Google Maps in the body tag? wordpress wordpress

How to initialize Google Maps in the body tag?


No you don't want to be adding another body tag into the specific page template that uses the map. Your opening <body> tag will be in header.php , you should get the page ID of the specific page which you want to load it on and do;

<body <?php if (is_page(374)) { echo 'onload="initialize()" onunload="GUnload()"'; } ?>>

in header.php

Which will add that code to (in my instance) page 374.

To find the page id, just hover over it in the Pages section in the backend and you can see the ID in the link url.

For multiple pages you would use;

<body <?php if (is_page(array(374,375))) { echo 'onload="initialize()" onunload="GUnload()"'; } ?>>

and you can also use the slug or title instead of ID, but of course they are easy for your client to change and stop that code working. Here's the codex link on is_page;

http://codex.wordpress.org/Function_Reference/is_page