WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got jwplayer installed in wordpress and have it showing in a single.php page... the way I have it I need to get a custom field in the javascript and I;m having no luck echoing it in there. I know you cant straight up run PHP in a javascript function, hence I'm here asking noob questions :)

<script type='text/javascript'>
'flashplayer': '/wp-content/uploads/jw-player-plugin-for-wordpress/player/player.swf',
'image': '/wp-content/themes/sometheme/images/vid.png',
'file': '<?php echo get_post_meta($post->ID, 'video', true); ?>',
'skin': '/wp-content/plugins/jw-player-plugin-for-wordpress/skins/skewd.zip',
'stretching': 'exactfit',
'controlbar': 'bottom',
'width': '640',
'height': '360'

is it possible to get

<?php echo get_post_meta($post->ID, 'video', true); ?>

Running in there for the file path?

Thanks for any advice.

share|improve this question
up vote 1 down vote accepted

Have a read through this article:

Adding Scripts Properly to WordPress Part 2 – JavaScript Localization

What you are doing here is passing your PHP values to the WordPress JS localization system. This then allows your JS code to get access to those variables you have passed.

share|improve this answer
Thanks! this is exactly what I've been searching for! – DOA Jul 7 '11 at 13:05

Echo out the JavaScript in your header.php file


echo '<script type="text/javascript">'; 

echo 'loads of JavaScript code';

echo get_post_meta($post->ID, 'video', true);

echo '</script>'; 

share|improve this answer
Shouldn't be putting JS in the header unless absolutely necessary. Secondly there are much better ways sending PHP variables to JS – Brady Jul 7 '11 at 12:44
Yeah, it's nasty and crude, but hey, when you need a fix! – tim Jul 7 '11 at 12:46
Seems to do the job fine :) but I'll look into the recommended wordpress methods. Thanks for helping out! – DOA Jul 7 '11 at 13:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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