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.

2 Answers 2


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.


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>'; 

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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