Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 633033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:08:27+00:00 2026-05-13T20:08:27+00:00

Is it possible (and if so please explain how) to echo php into javascript,

  • 0

Is it possible (and if so please explain how) to echo php into javascript, specifically for my purpose I am trying to echo the input of a custom field from the wordpress platform into the description of a google map. I am hoping I can give the client a cms backend to input the text that appears in the marker points on a map. What I am trying with no success is:

var point = new GLatLng(49.295308,-123.149297);
var marker = createMarker(point,"Site Title",'<div class="maptext"><p class="prepend-top caption">Title<\/p>

    <?php $the_query = new WP_Query('category_name=featured');
    while ($the_query->have_posts()) : $the_query->the_post();?>
    <?php if ( get_post_meta($post->ID, 'site-description', true) ) { ?>
    <?php echo get_post_meta($post->ID, 'site-description', $single = true); ?>
    <?php } ?>
    <\/div>')
          map.addOverlay(marker);

ok sarfaz was right with his orignal response and I was getting a parse error which was breaking it. what finally worked was this:

 var point = new GLatLng(48.134239,-122.764769);
      var marker = createMarker(point,"Port Townsend Marine Science Center",'<div class="maptext"><?php $the_query = new WP_Query('post_name=test-site');
while ($the_query->have_posts()) : $the_query->the_post();?><?php if ( get_post_meta($post->ID, 'map-content', true) ) { ?><?php echo get_post_meta($post->ID, "map-content", $single = true); ?><?php } ?><?php endwhile; ?><\/div>')
      map.addOverlay(marker);  

— UPDATE —

Just wanted to add that I found this to be the best way for me to grab posts since I always want a specific one linked to that marker :

  var point = new GLatLng(48.5139,-123.150531);
  var marker = createMarker(point,"Lime Kiln State Park", 
    '<?php $post_id = 182;
$my_post = get_post($post_id);
$title = $my_post->post_title;
echo $title;
echo $my_post->post_content;
?>')
      map.addOverlay(marker);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:08:28+00:00Added an answer on May 13, 2026 at 8:08 pm


    Yes, that is surely possible to have php echoed in javascript code. In your code you are missing the endwhile so only first subsequent line of your code is executing causing you unexpected result.

    Update: Try t his:

    var point = new GLatLng(49.295308,-123.149297);
    var marker = createMarker(point,"Site Title","<div class=\"maptext\"><p class=\"prepend-top caption\">Title</p>
    
        <?php $the_query = new WP_Query('category_name=featured');
        while ($the_query->have_posts()) : $the_query->the_post();?>
        <?php if ( get_post_meta($post->ID, 'site-description', true) ) { ?>
        <?php echo get_post_meta($post->ID, 'site-description', $single = true); ?>
    
        </div>")
              map.addOverlay(marker);
        ..................
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want this to work, you can use List<T>… May 14, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer I think you might need to use the -L switch… May 14, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer You need to wrap your code to run on document.ready,… May 14, 2026 at 6:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.