Title: Using Shortcodes in themes
Last modified: August 19, 2016

---

# Using Shortcodes in themes

 *  [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/)
 * I’m using the ProPlayer plugin, that uses a shortcode [pro-player]value[/pro-
   player]
 * I would like to show the most recent video in the sidebar. So my plan is to use
   a ‘video’ custom field and put the video posts in a videos category. Then I can
   display the video custom field of the first post in the videos category. Which
   will be the most recent video…
 * But I’ve run into a wall due to the shortcode. From what I’ve read, there are
   certainly ways to use shortcodes in themes, but everything I do just outputs 
   the normal bracketed text.
 * Here’s the something that I’ve tried:
 *     ```
       <?php // if there's a video
       if($video !== '') { ?>
       <?php echo do_shortcode('[pro-player]$video[/pro-player]'); ?>
       <?php } // end if statement
   
       // if there's not a thumbnail
       else { echo ''; } ?>
       ```
   
 * Which ouputs
 * > [pro-player]$video[/pro-player]
 * I’ve also tried
 *     ```
       <?php // if there's a video
       if($video !== '') { ?>
       <?php echo do_shortcode("[pro-player]'$video'[/pro-player]"); ?>
       <?php } // end if statement
   
       // if there's not a thumbnail
       else { echo ''; } ?>
       ```
   
 * Which shows
 * > [pro-player]’[http://www.youtube.com/watch?v=UF8Cs2gqXfk'%5B/pro-player%5D](http://www.youtube.com/watch?v=UF8Cs2gqXfk&apos;%5B/pro-player%5D)
 * What ever that means…
 * Any help would be greatly appreciated. Thanks

Viewing 14 replies - 1 through 14 (of 14 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139730)
 * Shortcodes need to be within the content section of a post or page in order to
   be parsed (converted) into markup that can be displayed on a page. Occasionally
   a plugin does incorporate an ability to add its functionality outside of the 
   page content area. But that does depend upon the plugin. And possibly your ability
   to delve into the plugin’s code and isolate the right code snippet to use.
 *  [isa.goksu](https://wordpress.org/support/users/isagoksu/)
 * (@isagoksu)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139795)
 * [@chase](https://wordpress.org/support/users/chase/), [@esmi](https://wordpress.org/support/users/esmi/)
 * With 4.5.1 the only thing you need to do is using single-use syntax. For above
   video you could do:
 *     ```
       <?php proplayer("[pro-player]http://www.youtube.com/watch?v=UF8Cs2gqXfk[/pro-player]"); ?>
       ```
   
 * Best,
    Isa Goksu
 *  Thread Starter [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139858)
 * I’m so glad you found this, thanks to you both for the responses!
 * I updated the plugin, and the code you provided works great. The only problem
   is I’m trying to show the most recent video, rather than a specific one.
 * My plan was to do this through custom fields, so that I can show the ‘video’ 
   custom field of the most recent post in the video category. And then that will
   give me the most recent video.
 * So rather than use the youtube link in your example, I used my custom field. 
   At first it didn’t work, but then I put quotes around it and now it looks like
   it’s working fine.
    `<?php echo proplayer("[pro-player]'$video'[/pro-player]");?
   >`
 * I am receiving some type of error in IE though. It happens with your original
   code as well.
 * Here’s a link to the test site: [http://clan-ngru.com/justatest/uncategorized/hello-world/](http://clan-ngru.com/justatest/uncategorized/hello-world/)
 * Thanks again for the help
 *  Thread Starter [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139878)
 * Actually that wasn’t working right. The player was loading but it couldn’t find
   the video. I fiddled with it some more, and this seems to work better: `<?php
   echo proplayer("[pro-player]$video;[/pro-player]"); ?>`
 * But I’m still getting an error, and it can’t find the preview image. (maybe they’re
   connected)
 * The error is this:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load
   Never Completed.
 * Thanks again
 *  [isa.goksu](https://wordpress.org/support/users/isagoksu/)
 * (@isagoksu)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139949)
 * [@chase](https://wordpress.org/support/users/chase/), could you send me a test
   url? This sounds like a weird problem.
 * Isa
 *  Thread Starter [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1139990)
 * sure, [http://clan-ngru.com/justatest/uncategorized/hello-world/](http://clan-ngru.com/justatest/uncategorized/hello-world/)
 *  [isa.goksu](https://wordpress.org/support/users/isagoksu/)
 * (@isagoksu)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140022)
 * [@chase](https://wordpress.org/support/users/chase/), I don’t see any problem.
   I watched a modern warfare 2 trailer.. You still have the problem?
 *  Thread Starter [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140034)
 * Hey Isa, thanks for taking a look.
 * Yes, the video plays properly when you hit play, but the preview image from Youtube
   is not displaying, and when using IE an error occurs
 * > Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.
 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140037)
 * I’m trying to do exactly the same. My php knowledge isn’t good enough to insert
   a custom field in-between the code. Please help.
 *     ```
       <?php query_posts('showposts=1&cat=18'); ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <?php proplayer("[pro-player] <strong>THIS IS WHERE I WANT THE CUSTOM FIELD TO APPEAR</strong> [/pro-player]"); ?>
   
       <?php endwhile; ?>
       ```
   
 * That’s my code.
 *  [isa.goksu](https://wordpress.org/support/users/isagoksu/)
 * (@isagoksu)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140038)
 * [@chase](https://wordpress.org/support/users/chase/) you have to strip out the‘;’–
   semicolon at the end of your URL’s. You’re using like:
 *     ```
       proplayer("[pro-player]$video;[/pro-player]"); ?>
       ```
   
 * you should try this:
 *     ```
       proplayer("[pro-player]$video[/pro-player]"); ?>
       ```
   
 * Preview images are mostly based on video ids. In this case your video id ends
   with semicolon which originally it shouldn’t be there. ProPlayer cannot strip
   all the characters since other video sources sometimes use those characters. 
   YouTube doesn’t accept semicolon but Vimeo on the other hand has lots of semicolons
   in its backend urls. I don’t know if it makes sense. Anyways just remove the 
   semicolon and enjoy 🙂
 * [@zefdesign](https://wordpress.org/support/users/zefdesign/), that code should
   work (I presume that u’re not using HTML tags in between [proplayer] tags). What’s
   ur problem?
 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140039)
 * Sorry I wasn’t clear there. I don’t know what code I need to put between the [
   pro player] tags to make my custom field called **music_url** appear there.
 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140040)
 *     ```
       <?php query_posts('showposts=1&cat=18'); ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <?php echo proplayer("[pro-player]$video_url[/pro-player]"); ?>
   
       <?php endwhile; ?>
       ```
   
 * That’s my code and it isn’t working… I apologise if anything im saying here is
   beyond stupid.
 *  Thread Starter [chasew](https://wordpress.org/support/users/chasew/)
 * (@chasew)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140042)
 * zef, make sure you have this somewhere above that. (unless there is something
   wrong with my custom field code)
 *     ```
       <?php
       // check for video
       $video_url = get_post_meta($post->ID, 'Video-URL', $single = true);
       ?>
       ```
   
 * Where it says Video-URL, change that to what ever your custom field actually 
   is on the edit page. And it IS case sensitive.
 * isa, thank you for the continued support. Still having trouble though.
    I stripped
   the semicolon out of the theme code, and made sure that the custom field entry
   in the post didn’t have one either, and still I’m still having issues.
 * I found a new video to try. I did a test post using the normal shortcode on the
   edit page here: [http://clan-ngru.com/justatest/uncategorized/normal-test/](http://clan-ngru.com/justatest/uncategorized/normal-test/)
 * This is the url that I used between the shortcode: [http://www.youtube.com/watch?v=dDfpsVDjIWo](http://www.youtube.com/watch?v=dDfpsVDjIWo)
 * In that post, the video plays fine, working preview image, no errors in IE.
 * Now here is my other test post, where I’m using the custom field method. The 
   video url in the custom field is the same as above, with no semicolon
 * [http://clan-ngru.com/justatest/uncategorized/custom-field-test/](http://clan-ngru.com/justatest/uncategorized/custom-field-test/)
 * Yet for some reason, when I remove the semicolon from the theme, I get the following
   error in the browser:
 * > Parse error: syntax error, unexpected ‘/’, expecting T_STRING or T_VARIABLE
   > or T_NUM_STRING in /home/content/n/g/r/ngruhq/html/justatest/wp-content/themes/
   > default/single.php on line 31
 * If I add the semicolon back, the video plays fine, but with no preview image 
   and the same actionscript error in IE.
 * If you would be willing, I can send you the admin login information to play with
   and you can edit the single.php file in the WordPress editor to play with the
   themes code.
 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140046)
 * Brilliant, thank you so much for helping me there!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Using Shortcodes in themes’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 14 replies
 * 4 participants
 * Last reply from: [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/using-shortcodes-in-themes/#post-1140046)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
