0

I want to show a jQuery flot graph on a WordPress blog. (EDIT: A post, just to be clear.)

I've got the flot graph working outside WordPress, but the (lack of) documentation and (millions of conflicting) forum questions about getting jQuery plugins working with WordPress are very confusing.

What do I need to do to use the flot plugin with WordPress?

I'm guessing:

  • Add a reference to jQuery somewhere in the WordPress post. Apparently jQuery is bundled with WordPress, but it's not included by default in the head, so how do I refer to it?
  • Add a reference to flot in the WordPress post. I've installed the WordPress flot plugin, but where is the actual JavaScript file? (The documentation doesn't say!)
  • Add my flot script inside document.ready - some forum posts refer to the need to change $ to jQuery when using WordPress: do I need to do this?

Thanks for this. I think someone who wrote a definitive post on "Using jQuery Plugins With Wordpress" would get a lot of very grateful traffic.

1 Answer 1

0
wp_register_script('flot', plugins_url('/flot/jquery.flot.min.js', __FILE__), array("jquery", "jquery-ui-core", "excanvas" ), '0.7.0');

(taken from flot.php)

8
  • That just comes out as unescaped HTML. Do I need to enclose it in PHP tags? Install exec-PHP plugin? When I do both those things, I get "Exec-PHP WYSIWYG Conversion Warning. Saving this article will render all contained PHP code permanently unuseful. Even if you are saving this article through the Code editor." - AAAAAARGH.
    – Richard
    Oct 12, 2011 at 14:33
  • Would be a lot easier just to refer to the jQuery and flot scripts. They must be somewhere in the filesystem, right? I could use CDN-hosted jQuery, so all I need to do is find the flot script. Where is it?
    – Richard
    Oct 12, 2011 at 14:34
  • '/flot/jquery.flot.min.js' is the path relative to your plugin-directory. This is nothing you have to insert, it should already been loaded in the page (look at the rendered HTML source code for query.flot.min.js )
    – campino2k
    Oct 12, 2011 at 14:37
  • Sorry, I don't understand. (1) Do I need to insert the wp_register_script tag in the body of the Wordpress post? (2) If so, I think I need to wrap it in PHP tags, and install a plugin to get PHP to execute, right?
    – Richard
    Oct 12, 2011 at 14:41
  • Thanks, but how do I get wp_register_script to register in the post, then? I've pasted it in to the HTML editor and it's rendering as unescaped HTML. To be clear: I simply don't understand how to get this script into the post.
    – Richard
    Oct 12, 2011 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.