E
E
Evgeny Ermolaev2015-03-24 12:06:12
API
Evgeny Ermolaev, 2015-03-24 12:06:12

How to make 2gis API work in Wordpress?

I can't connect 2gis api to wordpress. The following error is displayed:

Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: (min-resolution: 144dpi)

During the build, everything worked great. It does not work exactly when the template is connected. I
tried to connect the API in two ways:
1. Through functions.php
wp_register_script('mapapi', 'http://maps.api.2gis.ru/2.0/loader.js?pkg=full&lazy=true');
wp_enqueue_script('mapapi');

But the problem is that the connection of the script must be accompanied by the obligatory attribute data-id="dgLoader" and does not want to be connected at all
2. Through header.php with a condition (because I need this api only on one page)
<?php if (is_page('contacts')){?>
    <script src="http://maps.api.2gis.ru/2.0/loader.js?pkg=full&lazy=true" data-id="dgLoader" ></script>
<?php } ?>

This method is more like the truth, but displays the error described above.
Tell me, what other ways can be added?
PS Plugins (if any) do not offer. I think the problem can be solved without resorting to dubious extensions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2015-03-24
@patch94

this is not a mistake but a recommendation
to connect correctly like this

function my_script() {
if ( is_page('contacts') )
  wp_enqueue_script('my-script','http://maps.api.2gis.ru/2.0/loader.js?data-id');
}

add_action( 'wp_enqueue_scripts', 'my_script' );


add_filter('clean_url','unclean_url',10,3);
function unclean_url( $good_protocol_url, $original_url, $_context) {
  if ( false !== strpos( $original_url, 'data-id' ) ) {
    remove_filter( 'clean_url', 'unclean_url', 10, 3 );
    $url_parts = parse_url( $good_protocol_url );

    return $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'] . '?pkg=full&lazy=true'."' data-id='dgLoader";
  }

  return $good_protocol_url;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question