Title: PHP function into the main Javascript
Last modified: August 30, 2016

---

# PHP function into the main Javascript

 *  [manu-oswald](https://wordpress.org/support/users/manu-oswald/)
 * (@manu-oswald)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/php-function-into-the-main-javascript/)
 * Great plugin, martynasma, really great.
 * I am trying to set a really simple widget, starting from the default “Zooming
   to Countries Map”, which will have next to each country name the count of posts
   published for that country (the categories are the country names, I have a travel
   blog :)).
 * I am trying to include some PHP code to dynamically get the post count by category,
   but actually I don’t know if it’s possible to add php code in it, since neither
   the simplest echo uses to work, as you can see in my code below:
 *     ```
       var map = AmCharts.makeChart("chartdiv", {
       	"type": "map",
               "theme": "none",
       	"pathToImages": "http://www.amcharts.com/lib/3/images/",
   
       	"dataProvider": {
            "map": "worldLow",
            "getAreasFromMap": true,
             "areas": [{"id": "US","title":"United States ("+<?php echo '16' ?>+")"}]
       	},
       	"areasSettings": {
       		"autoZoom": true,
             	"color": "#0063be",
             	"rollOverColor": "#ffb511",
       		"rollOverOutlineColor": "#ffffff",
             	"selectedColor": "#ffb511",
             	"outlineThickness": 2
       	},
       	"smallMap": {}
       });
       ```
   
 * Could you please help me to achieve what I need?
 * Thank you
 * [https://wordpress.org/plugins/amcharts-charts-and-maps/](https://wordpress.org/plugins/amcharts-charts-and-maps/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/php-function-into-the-main-javascript/#post-6719517)
 * Hi there.
 * Sorry for not getting back to you. Somehow I missed your post.
 * No, you can’t use PHP code in the chart’s code. That would be extremely insecure.
 * One solution would be to add a code to your theme or some custom plugin that 
   would output your data as a JavaScript. I.e. it could produce something like 
   that:
 *     ```
       <script>
       var counts = {
         "US": 16
       };
       </script>
       ```
   
 * Then your map code could refer to this variable:
 *     ```
       "areas": [{
         "id": "US",
         "title":"United States ("+ counts["US"] +")"
       }]
       ```
   
 * I hope this helps.

Viewing 1 replies (of 1 total)

The topic ‘PHP function into the main Javascript’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amcharts-charts-and-maps_6f74b0.svg)
 * [amCharts: Charts and Maps](https://wordpress.org/plugins/amcharts-charts-and-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amcharts-charts-and-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amcharts-charts-and-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amcharts-charts-and-maps/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [map](https://wordpress.org/support/topic-tag/map/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 1 reply
 * 2 participants
 * Last reply from: [martynasma](https://wordpress.org/support/users/martynasma/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/php-function-into-the-main-javascript/#post-6719517)
 * Status: not resolved