Support » Fixing WordPress » Trying to add Javascript via Shortcode

  • Resolved deziiner


    Hi all.

    I’m using jPlayer to add music streaming to my website, and to do so, I’m trying to implement it via WP Shortcode. I want to use the following shortcode to call the jPlayer playlist file:

    [stream playlist=””]

    And it should return, with the other called files:

    <script type=”text/javascript” src=””></script>

    And here’s the full shortcode code to show you what I’m doing:

    // [stream playlist=””]
    function getPlayer($atts, $content = null) {
    “playlist” => ‘’,
    ), $atts));
    $showstream = ‘<style type=”text/css”>@import url(“‘ . bloginfo(‘template_directory’) . ‘/css/jplayer.single.doubledance.css”);</style>’;
    $showstream .= ‘<script type=”text/javascript” src=”‘ . bloginfo(‘template_directory’) . ‘/js/jquery.jplayer.min.js”></script>’;
    $showstream .= ‘<script type=”text/javascript” src=”‘ . $playlist . ‘”></script>’;
    return $showstream;
    add_shortcode(“stream”, “getPlayer”);

    But WordPress strips all javascript of its script tags, so my question is, how do I implement javascript via my shortcode?


Viewing 2 replies - 1 through 2 (of 2 total)
  • You could take a look at my Plugin called Contemplate:

    In the admin options you can define blocks of text/html/javascript etc. and then add it into any posts/pages via a simple shortcode. Plugin has flexible options, see the screenshots etc. and see if it is what you need.

    Hope it helps. 🙂

    Hey thanks for your help! Turn out I had errors in my code, that’s why it wasn’t working! Apparently WordPress DOES allow Javascript to be passed through shortcodes.

    Thanks though!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to add Javascript via Shortcode’ is closed to new replies.