• Resolved iansane

    (@iansane)


    Hi,

    I had a hard time a couple weeks ago with trying to use starkers wp theme framework because it uses htaccess to rewrite urls for javascripts and css so the html5 can get access to reset.css, jquery, and modernizr.js.
    I finally figured out it was using htaccess and I needed to fix permissions so it could write to it.

    During my search I saw several references to using wp_localize in the functions.php being the correct way to add external libs to the head but found out today that I can use bloginfo(‘template_directory’) to get to the css and js directories in my theme’s folder.

    So my question is, why not use the ‘template_directory’ method? Is there something insecure about it? I ask because it seems like the simplest way and I can easily add jquery at the end of the body for faster page loading so I’m wondering if there is a reason this method wasn’t the one I found googling. Are there cons to doing it this way?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The currently supported version of jQuery is included with each WP build…that said, creating a fast CDN can help with slow (shared) hosts.
    How that is implemented is typically theme and host specific.

    If you take a look at the header.php file in the toolbox theme (the official WordPress HTML5 starter theme) you’ll see the following code:

    <link rel="profile" href="https://gmpg.org/xfn/11" />
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
    <?php if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); ?>
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
    <![endif]-->

    which is doing exactly as you propose. The other way to add extra js libraries is to use code like:

    if( !is_admin()){
       wp_deregister_script('jquery');
       wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1');
       wp_enqueue_script('jquery');
    }

    to your functions.php file and let WordPress add the library. This has the advantage that it handles conflicts when multiple plugins require the same library.

    /peter

    The version of jQuery included in 3.2.1 was not complete, it was a stripped down version that only included the features WordPress needed. I don’t know if this has been fixed in 3.3 or not. That’s why the wp-deregister call appears in the code I posted.

    /peter

    Using external scripts, no matter who from, leaves you at their mercy…get better host.

    Thread Starter iansane

    (@iansane)

    Thanks for the info on toolbox and the code examples pkwooster. I’m glad to see that. I wonder why starks(think I spelled that wrong earlier) is using htaccess rewrite instead.

    SwansonPhotos,
    I may have complicated the question. My host is fine. I am trying to learn how to build html5 wordpress themes and I want to make sure modernizr.js and my reset.css and any other scripts I include stay inside the theme directory with the theme. I was just having a hard time figuring out how to include them in the index.php since the static html way of linking through relative path doesn’t work. I think starks may be way over complicated and trying to do too much for something that is supposed to be like a boiler plate for a theme and it confused me.

    I’m going through some nettuts tutorials and it’s starting to come together now.

    Thank you both for the replies

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘question about using external libs in a theme’ is closed to new replies.