WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode - How to call the url in the code (3 posts)

  1. Esperanza55
    Member
    Posted 5 months ago #

    Hello,

    I created my first shortcode. It was difficult but after several errors and trying again and again, it finally works. Now I'd like to improve it.

    How can I have the path of the 2 files you will see in my code without writing all the path? I tried all the afternoon but not succeed; I do not know enough php.

    For the skin file, I tried:

    'skin' => "'. plugins_url() .'/jwplayer/six.xml",

    But it returns : Error loading skin : File not found.

    It seems that it is a little bit more complicated to do… Thank you in advance for your help. Sorry for my bad English.

    PS: I know that exists a WordPress plugin for JWPlayer but I do not want to use it.

    Here is the code that works:

    function jo_video_jw($atts){
    	extract(shortcode_atts(array(
    		'myElement' => "myElement",
    		'width' => "100%",
    		'aspectratio' => '',
    		'autostart' => "false",
    		'file' => '',
    		'skin' => "http://localhost/xxx/wp-content/plugins/jwplayer/six.xml",
    		'image' => "http://localhost/xxx/wp-content/uploads/videos/messe.jpg"
    	), $atts));
    
    	$return = '<div id="'.$myElement.'">Loading the player...</div>
    
    <script type="text/javascript">
    {
    	jwplayer("'.$myElement.'").setup({
    	  autostart: "'.$autostart.'",
    	  image: "'.$image.'",
    	  width: "'.$width.'",
    	  aspectratio: "'.$aspectratio.'",
    	  skin: "'.$skin.'",
    	  file: "'.$file.'",
    	  });
    }
    </script>';
    	return $return;
    }
    add_shortcode('video_jw','jo_video_jw');
  2. Matt
    Member
    Posted 5 months ago #

    Is this what you're looking for?

    Plugin path

    Uploads path

  3. Esperanza55
    Member
    Posted 5 months ago #

    Hello Matt,

    Thank you for your reply.

    Yes probably but I don’t know how to apply it. This is an hour that I am trying but not succeed. As I said I don’t know php and I cannot take a course of php for writing two lines… This is the only thing that is missing to complete the site.

    Here's the code I tried, am I in the right direction?

    $upload_dir = wp_upload_dir();
    function jo_video_jw($atts){
    	extract(shortcode_atts(array(
    		'myElement' => "myElement",
    		'width' => "100%",
    		'aspectratio' => "16:9",
    		'autostart' => "false",
    		'file' => '',
    		'skin' => "http://localhost/xxx/wp-content/plugins/jwplayer/six.xml",
    		'image' => "<?php echo $upload_dir['baseurl']; ?>/videos/messe.jpg"
    	), $atts));

    Thanks again.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.