I am trying to echo some javascript but it is making it as text, it works fine on my test page but when I add it to wordpress it turns it into text. But I have another part where the script runs fine.
echo '
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.
var placeSearch, autocomplete;
var componentForm = {
street_number: \'short_name\',
route: \'long_name\',
locality: \'long_name\',
administrative_area_level_1: \'short_name\',
country: \'long_name\',
postal_code: \'short_name\'
};
function initialize() {
// Create the autocomplete object, restricting the search
// to geographical location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */(document.getElementById(\'autocomplete\')),
{ types: [\'geocode\'] });
// When the user selects an address from the dropdown,
// populate the address fields in the form.
google.maps.event.addListener(autocomplete, \'place_changed\', function() {
fillInAddress();
});
}
// [START region_fillform]
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = \'\';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
// [END region_fillform]
if (typeof jQuery != \'undefined\') {
alert("jQuery library is loaded!");
}else{
alert("jQuery library is not found!");
}
jQuery(document).ready(function () {initialize();});
</script>
<style>
#autocomplete {
top: 0px;
left: 0px;
width: 350px;
}
</style>
</head>
<div>
';
I know that the code works, just that the echo doesn't. Please help.
Sorry for the sloppy code :[
Output :
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script><br />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><br />
<script>
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.</p>
<p>var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};</p>
<p>function initialize() {
// Create the autocomplete object, restricting the search
// to geographical location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {HTMLInputElement} */(document.getElementById('autocomplete')),
{ types: ['geocode'] });
// When the user selects an address from the dropdown,
// populate the address fields in the form.
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
});
}</p>
<p>// [START region_fillform]
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();</p>
<p> for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}</p>
<p> // Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
// [END region_fillform]</p>
<p>if (typeof jQuery != 'undefined') {</p>
<p> alert("jQuery library is loaded!");</p>
<p>}else{</p>
<p> alert("jQuery library is not found!");</p>
<p>}</p>
<p>jQuery(document).ready(function () {initialize();});</p>
<p> </script></p>
<style>
<p> #autocomplete {
top: 0px;
left: 0px;
width: 350px;
}</p>
</style>
includethem.