Search code examples
javascriptphpwordpressyandex-maps

api yandex maps on different pages of wordpress site


I have 4 pages in wordpress site where i need to inculde api yandex maps. So i created 4 scripts, which works. I included script tags in my footer:

        <!-- Yandex map scripts -->
    <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="application/javascript"></script>
    <script src="/wp-content/themes/bla" type="application/javascript"></script>
    <script src="/wp-content/themes/blabla" type="application/javascript"></script>
    <script src="/wp-content/themes/blablabla" type="application/javascript"></script>
    <script src="/wp-content/themes/blablablabla" type="application/javascript"></script>

All scripts have different ids for div blocks, different variable names. But when i put my divs inside 4 pages, only the first script is working, in this example i will see map only on the page that contains this script

<script src="/wp-content/themes/bla" type="application/javascript"></script>

Other pages will be blank.

In browser it looks like this, so script is not working

If i load all 4 maps on 1 page it is working. But i want each map on certain page.

What should i do to get things work?


Solution

  • Problem solved. I guess we have to load yandex json every time.

    <!-- Yandex map scripts --> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <script src="/wp-content/themes/bbbb" type="application/javascript"></script> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <script src="/wp-content/themes/b" type="application/javascript"></script> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <script src="/wp-content/themes/bbb" type="application/javascript"></script> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <script src="/wp-content/themes/bb" type="application/javascript"></script> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>