• Resolved deziiner

    (@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=”https://example.com/playlist.js”%5D

    And it should return, with the other called files:

    <script type=”text/javascript” src=”https://example.com/playlist.js”></script&gt;

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

    // ADD SINGLE STREAM SHORT CODE
    // [stream playlist=”https://example.com”%5D
    function getPlayer($atts, $content = null) {
    extract(shortcode_atts(array(
    “playlist” => ‘https://example.com/playlist.js&#8217;,
    ), $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?

    Thanks!

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

    https://www.ads-software.com/extend/plugins/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. ??

    Thread Starter deziiner

    (@deziiner)

    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.