PHP path in Jquery

I am trying to integrate a mp3 player in WordPress using the following code:

 $(document).ready(function(){
        var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
            var path_php = "<?php bloginfo('template_directory'); ?>";

        $('body').ttwMusicPlayer(myPlaylist, {
            autoPlay:false, 
            description:description,
            jPlayer:{
                swfPath: path_php+'/plugin/jquery-jplayer' 
            }
        });
    });

In a weird way the player is working just in Opera and IE8. The script is correct integrated because it work if i write the absolute path of the blog for the var php_path.

Read More

Can help me with what i am missing? Thanks!

later edit: if you have an idea about a different approach of how to load a wp template path in above jquery code, i am open to it.

here is the browser output for the above code:

  $(document).ready(function(){
            var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
            var path_php = "http://localhost/mywebsite/wp-content/themes/mythemename";

            $('body').ttwMusicPlayer(myPlaylist, {
                autoPlay:false, 
                description:description,
                jPlayer:{
                    swfPath: path_php+'/plugin/jquery-jplayer' 
                }
            });
        });

Related posts

Leave a Reply

4 comments

  1. In wordpress

    plugins_url()
    

    brings back the plugin url including the domain.

    $(document).ready(function(){
        var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
            var path_php = "<?php print plugins_url(); ?>";
    
        $('body').ttwMusicPlayer(myPlaylist, {
            autoPlay:false, 
            description:description,
            jPlayer:{
                swfPath: path_php.match(/http://[^/]+(.*)/)[1]+'jquery-jplayer' 
            }
        });
    });
    

    So that should replace the http:// and domain with nothing, leaving you with just the plugin path and jquery-jplayer on the end.

  2. Hey I just wrote a script to convert mp3 links to an audio player: http://www.bottleofbrass.com/?p=85

    The Javascript code below uses jQuery to convert mp3 links to a flash player on the fly. It utilizes this flash player: http://flash-mp3-player.net.

    $(‘#main a’).each(function(){

    if($(this).attr(‘href’)!=undefined){

    match=$(this).attr(‘href’).match(/.(mp3)/);

    if(match!=null){
    href=$(this).attr(‘href’);
    text=$(this).text();

    player= ”+text+”+
    ”+
    ”+
    ”+
    ”+
    ”;

    p=$(this).parent();
    $(this).remove();
    $(p).append(player);
    }

    }

    });