Support » Fixing WordPress » rewrite jquery insertion functions script

  • Paul Irish wrote a new version of jquery insertion into the [HTML5 Boilerplate project that looks like this:

    <script src="//"></script>
        <script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>

    Here’s Paul’s explanation:

    I’m very interested to port this over verbatim for WordPress projects using the wp_enqueue_script.

    function add_jquery_script() {
          wp_deregister_script( 'jquery' ); // get rid of WP's jQuery
          wp_register_script( 'jquery_cdn', '//', array(), '1.0', true );
          wp_enqueue_script( 'jquery_cdn' );
          echo'<script>!window.jQuery && document.write(unescape(\'%3Cscript src="' . get_bloginfo('template_directory') . '/js/libs/jquery-1.4.2.min.js"%3E%3C/script%3E\'))</script>';

    Two main problems:

    1. First register script line spits out absolute path rather than relative. The double-forward slashes should not have WordPress’ URI preceding the link.
    2. The echo forces the code in at the top (because it likely doesn’t belong in this function in this way).

    It’d be cool to get both of these versions working with the wp_enqueue_script but I realize it’s likely not possible.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘rewrite jquery insertion functions script’ is closed to new replies.