Trying to add Javascript via Shortcode
-
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>
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’,
), $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!
- The topic ‘Trying to add Javascript via Shortcode’ is closed to new replies.