How To Put JavaScript in Wordpress Posts?

5 replies
Hello,

I want this chart to run on my wordpress website. Any suggestion would really help me.

Thanks
#javascript #posts #put #wordpress
  • Profile picture of the author saxatwork
    If you want to show only the chart in that page, why not use an iFrame instead of Javascript?

    You can use this plugin - WordPress › iframe « WordPress Plugins - and add the iframe using a shortcode.
    Signature

    "Be Still Like A Mountain And Flow Like A Great River"

    {{ DiscussionBoard.errors[8400068].message }}
    • Profile picture of the author mirza786
      Well I succeed in displaying Javascript graph in Gleam theme of Wordpress but seems like it is not support it because I tried changing to many other themes (including defaults one) and they are working nicely.....
      {{ DiscussionBoard.errors[8405975].message }}
  • Profile picture of the author David V
    If you really want to use inline JavaScript like that graph link, you could use a plugin like Scripts-and-Styles which allows you to use inline JS, CSS on a per page/post basis so you don't have to load it except on the page needed.
    {{ DiscussionBoard.errors[8406177].message }}
  • Profile picture of the author SteveJohnson
    OR - you could write yourself a simple WP shortcode handler that you can drop in your theme's function.php file. You could even make it into a plugin if you want so you can change themes.

    Put this in theme's functions.php file, at the end (you should just remove the closing ?> tag if it's there):
    PHP Code:
    add_shortcode'mirzachart''mirzachart_shortcode');
    function 
    mirzachart_shortcode(){
      return 
    '<script language="javascript" type="text/javascript" src="http://people.iola.dk/olau/flot/jquery.flot.js"></script>';

    Then just use the shortcode [mirzachart] in your post wherever you want to display the chart.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[8409365].message }}
    • Profile picture of the author mirza786
      Originally Posted by SteveJohnson View Post

      OR - you could write yourself a simple WP shortcode handler that you can drop in your theme's function.php file. You could even make it into a plugin if you want so you can change themes.

      Put this in theme's functions.php file, at the end (you should just remove the closing ?> tag if it's there):
      PHP Code:
      add_shortcode'mirzachart''mirzachart_shortcode');
      function 
      mirzachart_shortcode(){
        return 
      '<script language="javascript" type="text/javascript" src="http://people.iola.dk/olau/flot/jquery.flot.js"></script>';

      Then just use the shortcode [mirzachart] in your post wherever you want to display the chart.
      Seems this is nice idea but it is not working for me. I did it according to the instructions. BTW what do u mean by removing ?> at the end? It is giving me error...
      {{ DiscussionBoard.errors[8413292].message }}

Trending Topics