• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Using JavaScript Libraries in WordPress/StudioPress

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Using JavaScript Libraries in WordPress/StudioPress

This topic is: not resolved

Tagged: JavaScript WordPress StudioPress

  • This topic has 3 replies, 2 voices, and was last updated 12 years, 6 months ago by rfmeier.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • May 30, 2013 at 8:44 pm #43291
    rdr
    Participant

    Hi all, I'm new to all of this, so please excuse a newbie question.

    I've set up my first web site, self hosted through Webfaction. I'm using the latest version of WordPress and was impressed with StudioPress so bought the ProPack to try out all that they have to offer.

    I've been impressed with the wide variety of JavaScript libraries there are out there. One in particular, called two.js (see http://jonobr1.github.io/two.js), makes it seemingly easy to draw graphics right on a web page using the API they provide.

    I can get two.js to work just fine on an empty HTML page on my site so I know I'm on the right track. But I've had no luck getting it to work on one of my WordPress pages. The library is loading (I've confirmed that with Chrome's JavaScript Console), but nothing is drawn.

    I'd love help with getting two.js to work, but I realize that might be too specific a problem to ask about. More generally my question is, is there a right way to incorporate JavaScript libraries like two.js into my WordPress site?

    I'd appreciate any guidance on the right approach to do this (and remember, I'm pretty much a novice!)

    Thanks in advance for your help.

    -- Robert

    http://www.robertdelrossi.com
    June 2, 2013 at 7:56 pm #43736
    rfmeier
    Member

    Robert,

    How are you loading the javascript on your WordPress site?  How are you then calling the javascript library?


    Ryan Meier – Twitter

    June 4, 2013 at 10:54 am #44039
    rdr
    Participant

    Ryan -- I'm loading and then calling the Javascript library inside a script tags that I types into the the Text tab of the new post page in WordPress. I have been able to verify through debugging consoles that the load is working. I've also been able to execute simple, limited Javascript (such as writing text to the generated HTML) this way, so I know that my script tags are being respected.

    That said, I realize that just because some simple tests work, it doesn't mean I'm doing things the right way. For example, loading the two.js library into this page may be OK when you're using it on this page alone, but should it be loaded that way if I were to call it from ten different pages? I would think not (i.e., that it should be loaded from some central point once and then called repeatedly from various other pages).

    -- Robert

    June 4, 2013 at 11:05 am #44042
    rfmeier
    Member

    Robert,

    For loading a javascript library globally in a WordPress website, I recommend hooking the 'wp_enqueue_scripts' action.  From within the callback, use wp_enqueue_script().  From there you can determine what pages you want to script to load on; pages, posts, single pages, single posts, etc.  This will ensure the two.js script is loading once.

    I hope this helps.


    Ryan Meier – Twitter

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble