0

We want to create a short-code. The final output of the source code should be similar to the code mentioned below.

<script type="text/javascript" src="http://hosted.musesradioplayer.com/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'http://streams.museter.com:8002/;',
'codec':'mp3',
'volume':65,
'autoplay':true,
'buffering':5,
'title':'Radio%20Vermont',
'welcome':'WELCOME TO...',
'bgcolor':'#FFFFFF',
'skin':'mcclean',
'width':180,
'height':60
});
</script>

the above mentioned code, when ever we insert shortcode, url and codec variable will change...

we try with the following shortcode but its wrong... kindly help me...

<?
function playermp3($atts) {
    extract(shortcode_atts(array(
        "value" => 'http://',
        "width" => '180',
        "height" => '60',
        "codec"=> 'mp3',
        "volume" => '65',
        "autoplay"=>'true',
        "buffering"=> '5',
        "title"=> 'Radio%20Vermont',
        "welcome" => 'WELCOME TO...',
        "bgcolor"=>'#FFFFFF',
        "skin"=> 'mcclean',
    ), $atts));
    return '<script type="text/javascript" src="http://hosted.musesradioplayer.com/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'.$value.',
'codec':'.$codec.',
'volume':'.$volume.',
'autoplay':'.$autoplay.',
'buffering':'.$buffering.',
'title':'.$title.',
'welcome':'.$welcome.',
'bgcolor':'.$bgcolor.',
'skin':'.$skin.',
'width':'.$height.',
'height':'.$width.'
});
</script>';
}
add_shortcode("playermp3", "playermp3");

?>
  • How exactly URL and codec value change? Just them change? Also from code highlight your string opening/closing looks like it has issues. – Rarst Sep 14 '13 at 8:06
1

WordPress offers a function called wp_localize_script. That function is your best friend for situations like yours. There are plenty of examples here. But I leave you with this good tutorial:

http://pippinsplugins.com/use-wp_localize_script-it-is-awesome/

0

Change your part with this one and it should work just fine:

"url":".$value.",
"codec":".$codec.",
"volume":".$volume.",
"autoplay":".$autoplay.",
"buffering":".$buffering.",
"title":".$title.",
"welcome":".$welcome.",
"bgcolor":".$bgcolor.",
"skin":".$skin.",
"width":".$height.",
"height":".$width."

If you use apostrophe for return, then make sure to use quotation marks for the data inside. Or you can do the opposite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.