• Resolved Hugo

    (@hugogpropellerse)


    Ok, I’m trying to use the jQuery-placehold script by jgarber (https://github.com/jgarber623/jquery-placehold) in order to be able fake the placeholder form attribute for older browsers. But I can’t seem to be able to load the script correctly, and I can’t really figure out what’s wrong. I’m not 100% on PHP syntax, so I’m guessing it’s probably something wrong there.

    I’ve put this in the <head></head> of my header.php file (before the wp_head(); call )

    <?php
    function place_method() {
       // register your script location, dependencies and version
       wp_register_script('jquery.placehold',
           get_template_directory_uri() . '/js/jquery.placehold.js',
           array('jquery'),
           '1.0' );
       // enqueue the script
       wp_enqueue_script('jquery.placehold');
    }
    add_action('wp_enqueue_scripts', 'place_method');
    ?>
    <script type="text/javascript">
    		jquery().ready( function() {
    			jquery( "input, textarea" ).placehold( "something-temporary" );
    		});
    </script>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The php portion of that code would most likely go in your functions.php file

    That’s where scripts are enqueued from

    Then I’m guessing the script portion of that goes in /js/jquery.placehold.js (A file I’m guessing you need to create)

    I can’t speak to the validity of the code, just how to actuyally enqueue scripts in WP

    Thread Starter Hugo

    (@hugogpropellerse)

    Thanks, I’ve tried putting it in functions.php instead, without success.

    Thing is, the script works if I test it in a plain html page and reference it directly, it’s all valid. But as soon as I try to get WordPress to register and enqueue it, something goes wrong. It’s not the script itself or the URI, but something else – either in the enqueue part or the noConflict part.

    The script adds a class to jQuery, can there be some referencing problem there?

    esmi

    (@esmi)

    Is the script being called into the page correctly?

    Thread Starter Hugo

    (@hugogpropellerse)

    Ok, I solved it, I called the script before wp_head(); which of course was silly of me. I realized my mistake when Firefox kept throwing error messages that jQuery is not defined, when clearly it was. Thanks guys!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_enqueue_scripts and jQuery’ is closed to new replies.