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 have written a function to register a script in the admin interface.

function custom_admin_js() {
    $url = get_bloginfo('template_directory') . '/admin/admin.js';
    echo '<script type="text/javascript" src="'. $url . '"></script>';
add_action('admin_footer', 'custom_admin_js');

For some - for me unknown reason - this creates additional quotes surrounding the script.

"<script type="text/javascript" src="http://test121.uphero.com/wp-content/themes/news/admin/admin.js"></script>"

How do I remove the surrounding quotes?

share|improve this question

I am not sure about the extra quotes. The best way to include a java script file is with wp_enqueue_script() as indicated here in the codex.

The safe and recommended method of adding JavaScript to a WordPress generated page and WordPress Theme or Plugin is by using wp_enqueue_script(). This function includes the script if it hasn't already been included, and safely handles dependencies.

add_action( 'admin_enqueue_scripts', 'wpse8170_enqueue_scripts' );
function wpse8170_enqueue_scripts() {
    wp_enqueue_script( 'wpse8170-admin-js', get_template_directory_uri() . '/admin/admin.js', null, null, true );

When in doubt use the function designed to do what you want to do. Reinventing the wheel almost always creates new problems.

share|improve this answer

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.