Support » Plugin: Code Snippets » Add a javascript library

  • Resolved pauldotmac

    (@pauldotmac)


    Hi,

    I’m trying to add a javascript library – flot – to my website using your plugin. I have the following code in one of your snippets but I get 2 errors

    add_action(‘wp_head’, function(){?>
    <script src=’http://localhost/test/wp-content/scripts/jquery.flot.min.js&#8217; language=’javascript’ type=’text/javascript’></script>
    ?php });

    1) Expecting a } on line 3
    2) Expecting a ) on line 3

    line 3 is the last line: ?php });

    Thanks

    Paul

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You’re missing a < character on line 3: it should look like this: <?php });

    I recommend adding javascript libraries using this method instead:

    add_action( 'wp_enqueue_scripts', function () {
    
    	wp_enqueue_script(
    		'jquery-flot',
    		'http://localhost/test/wp-content/scripts/jquery.flot.min.js',
    		array( 'jquery' )
    	);
    } );

    Excellent, thank you for the rapid response and the alternative solution.

    Should have spotted the missing “<“, simple mistake, but thank you

    Plugin Author Shea Bunge

    (@bungeshea)

    No problem!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.