Forum Replies Created

Viewing 4 replies - 46 through 49 (of 49 total)
  • Thread Starter gyzhor

    (@gyzhor)

    Well, I’ve tried adding the script to functions.php without much luck; it just crashes the site. My script is pretty extensive (about 400 lines) and clearly something in there is disagreeing with the php.

    Thread Starter gyzhor

    (@gyzhor)

    So put my script into functions.php, then *not* link it to the header via wp_enqueue_script? Or do I still need to initialize it with that in the head? (and if so, why include a directory name as the get_template_directory_uri?)

    Thanks again for the help.

    Thread Starter gyzhor

    (@gyzhor)

    I think I’d tried it before, but to be sure I just tried it using:

    <?php
    function my_scripts_method() {
    	wp_enqueue_script(
    		'custom-script',
    		get_template_directory_uri() . '/my-script-name.js',
    		array( 'jquery' )
    	);
    }
    
    add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
    ?>

    in the <head>, but my function is still being reported as not defined.

    Thread Starter gyzhor

    (@gyzhor)

    I have, and unless I missed something, it suggests loading scripts using the <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/pathto/yourscript.js"></script>method for scripts in the template (which I’m attempting, as opposed to in posts, which I’m not).

    When I attempt this, I get an error saying that my function is undefined.

    As I mentioned, too, using <script type="text/javascript" src="pathto/yourscript.js"></script> results in the script injecting its contents below the main content area, rather than in its generated div.

    I dunno, does that seem to imply that the conflict is in my javascript itself? Does WP have difficulty with document.createElement(‘div’)? Should I change my dynamic divs’ names to avoid potential conflict?

Viewing 4 replies - 46 through 49 (of 49 total)