Title: Using PHP generated JS in a plugin
Last modified: August 19, 2016

---

# Using PHP generated JS in a plugin

 *  [jonkirkman](https://wordpress.org/support/users/jonkirkman/)
 * (@jonkirkman)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/using-php-generated-js-in-a-plugin/)
 * I’m trying to use get_bloginfo(‘url’) in a javascript file being generated but
   any WordPress functions I attempt to use come up undefined.
    Sorry if the scenario
   is slightly confusing. I’ll my best to explain.
 * This is in my main plugin file:
 *     ```
       function soundtrack_add_js() {
       wp_enqueue_script( 'jquery', '1.3.2' );
       wp_enqueue_script( 'soundtrack-js', WP_PLUGIN_URL.'/soundtrack/soundtrack-script.js.php' );
       }
   
       add_action('wp_print_scripts', soundtrack_add_js);
       ```
   
 * This is my js file:
 *     ```
       <?php
       $forward_url = (isset($_GET['forward_url'])) ? $_GET['forward_url'] : get_bloginfo('url');
       $script  = 'jQuery(document).ready(function(){';
       $script .= '	if (parent.myframe) {';
       $script .= '		jQuery("body").prepend("Framed.");';
       $script .= '	} else {';
       $script .= '		var url = window.location;';
       $script .= '		jQuery("body").empty().append(\'<p>New stuff</p><iframe id="myframe" name="myframe" src="\'+url+\'" width="100%" height="100%" frameborder="0" />\');';
       $script .= '	}';
       $script .= '});';
       echo $script;
       ?>
       ```
   
 * When php hits get_bloginfo(‘url’) it dies.
    Is there a specific time when WordPress
   functions such as get_option() become available? I would love to understand this
   more fully.
 * Thanks for any help on the matter.

Viewing 1 replies (of 1 total)

 *  [Nutrawee](https://wordpress.org/support/users/zeally/)
 * (@zeally)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/using-php-generated-js-in-a-plugin/#post-1218179)
 * Try `bloginfo('url');` instead

Viewing 1 replies (of 1 total)

The topic ‘Using PHP generated JS in a plugin’ is closed to new replies.

## Tags

 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * 1 reply
 * 2 participants
 * Last reply from: [Nutrawee](https://wordpress.org/support/users/zeally/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/using-php-generated-js-in-a-plugin/#post-1218179)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
