WordPress.org

Ready to get started?Download WordPress

Forums

Javascript in WordPress Plugin (4 posts)

  1. frent
    Member
    Posted 4 years ago #

    Hi, i'm trying to use Javascript in my own WordPress plugin.
    I've used this code:

    if (function_exists('wp_register_script')) {
    		$src = "/" . PLUGINDIR . "/XMLProductFeed/js/ReadXML.js";
    		wp_register_script('readxml', $src);
    	}

    but it shows nothing when I open the plugin page.
    Any ideas? I hope it is not something stupid...

  2. deanhoover
    Member
    Posted 4 years ago #

    you need to use wp_enqueue_script. I have a follow up question. If I use enqueue do I need to use register?

    Dean

  3. Russell Heimlich
    Member
    Posted 4 years ago #

    A script needs to be registered first before it can be enqueued. http://codex.wordpress.org/Function_Reference/wp_enqueue_script

  4. Matty Cohen
    Member
    Posted 4 years ago #

    Hey frent, deanhoover, kingkool68,

    Enqueuing Javascript in WordPress seems to be a regular topic of conversation. I have had similar issues in the past, including Javascript conflicts caused by incorrectly included Javascript.

    Please see my blog post on Javascript and WordPress - The Definitive Guide for a detailed explanation of how to enqueue Javascript within WordPress plugins and themes.

    I hope this helps. :)

    Cheers,
    Matty.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags